Observable Semantics for Constraint Logic Programs

نویسندگان

  • Maurizio Gabbrielli
  • Giovanna M. Dore
  • Giorgio Levi
چکیده

versions of the immediate consequence operators that we will introduce canbe used for bottom-up abstract interpretation (i.e. xpoint computation of the ab-stract model). Abstract interpretation of CLP programs has been considered in adenotational semantics framework in [38], while we can generalize the bottom-up ap-proach in [3]. More interestingly, the compositional semantics can be used to developa framework for the modular analysis of CLP programs. This is particularly relevantfor practical applications where modularity can help to reduce the size and the com-plexity of the analysis. The semantics for partial answers and call patterns can be usedfor the analysis of programs too. For example, informations on partially computedconstraints can be used to detect \independence" of (sub)goals [25], thus providingthe conditions for optimizations of CLP programs based on AND-parallelism andintelligent backtracking.The paper is organized as follows. In the next section we recall the basic de nitionsof the CLP framework. In section 3 the new notion of -interpretation and of -modelare introduced. In section 4 we rst consider the derivation rule and introduce twoequivalences on programs based on di erent observable properties. Then we de netwo operational semantics modeling di erent observables and we discuss the \ground"success set de ned in [29]. The xpoint characterizations of all these semantics areshown in section 5, while section 6 is devoted to a discussion of the various -models.Section 7 introduces the compositional semantics and section 8 shows the semanticsfor partial answers and for call patterns. Finally, section 9 contains a discussion onsome applications of our constructions and an appendix includes some proofs andtechnical lemmata.A preliminary description of our semantics for computed answer constraints canbe found in [21].2 The language and its semantic domainsThe language we consider is CLP as de ned in [29, 28]. We also take some notationsfrom the recent survey on CLP languages by Ja ar and Maher [30]. Following [29]we are interested in a semantics in the typical logic programming style and we do notconsider other more \algebraic" approaches [39, 26].The CLP framework is de ned using a many-sorted rst order language. We havethen to introduce the standard de nition of many sorted (or, equivalently, S-sorted)signature.De nition 1 Given a set S of symbols (sorts), an S-sorted signature is a familyof disjoint sets of function symbols= f s1;:::;sn;sgs1;:::;sn;s2Swhere if f 2 s1;:::;sn;s we say that s1; : : : ; sn is the arity of f and s is the sort of f .An S-sorted signature with predicates is a pair h ; i where is an S-sorted signatureand is a family of disjoint sets of predicate symbols= f s1;:::;sngs1;:::;sn2Swhere s1;:::;sn is a set of predicate symbols. If p 2 s1;:::;sn we say that s1; : : : ; sn isthe arity of p.3 In the following, when no ambiguity arises, if = f s1;:::;sn;sgs1;:::;sn;s2S wedenote by also the set =Ss1;:::;sn;s2S s1;:::;sn;s. By a slight abuse of language, iff 2 s1;:::;sn;s we say also, according to the terminology used in [29], that s1; : : : ; sn; sis the signature of f , while if p 2 s1;:::;sn then s1; : : : ; sn is the signature of p. Weassume that there exists a family V = fVsgs2S where Vs is an in nite (denumerable)set of variables for the sort s. The S-sorted signature with predicates h ; i andthe family of variables V are the non logical symbols of the many sorted rst orderlanguage on which CLP programs are de ned. As usual we assume that the sets ;and V do not share any symbol. In the following the pair h ; i will denote such anS-sorted signature with predicates.( [ V ) and ( ) denote respectively the terms and the ground terms built onand V in the usual way. Formally( [ V ) = f ( [ V )sgs2Swhere, for any s 2 S, ( [ V )s is the least set such that1. Vs ( [ V )s,2. s ( [ V )s,3. if f 2 s1;:::;sn;s then, for any s; si 2 S and for any ti 2 ( [ V )si withi = 1; : : : ; n, f(t1; : : : ; tn) 2 ( [ V )s.( ) is obtained by setting V = ; in the previous de nition. If t 2 ( [ V )s wesay that t has sort s. A h ; i-atom is an element p(t1; : : : ; tn) where if p 2 s1;:::;snthen ti 2 ( [ V )si has sort si, i = 1; : : : ; n. A h ; i-constraint is a conjunction ofh ; i-atoms possibly existentially quanti ed1. The empty constraint will be denotedby true. The notations ~t, ~d and ~X will denote a tuple of terms, of domain elementsand of distinct variables respectively, while ~B will denote a ( nite, possibly empty)conjunction of atoms. The connectives \," and \^" will denote conjunction. Ingeneral, we will use interchangeably the notions of a conjunction of atoms and amultiset of the same.First order h ; i-formulas are constructed over the S-sorted signature using thelogical connectives and quanti ers in the usual way. A formula is closed if all variableoccurrences in the formula are within the scope of a quanti er over the variable. 9and 8 denote the existential and universal closure of the formula , respectively. A( rst-order) h ; i-theory is a collection of closed h ; i-formulas. According to thenotation of [30] 9 ~X will denote the existential closure of the formula except forthe variables ~X which remain unquanti ed.Given an S-sorted signature with predicates h ; i, throughout the paper we willassume that is de ned as the union of two given disjoint families of (disjoint) sets ofpredicate symbols C (for constraints) and B (for user de ned predicates). Moreoverwe assume that C contains the equality symbol = (which needs no signature). Wewill refer to these assumptions saying that is determined by C and B . Let usnow de ne the syntax of CLP programs.1Actually, generic rst order formulas can be used as constraints (see for example [30]). We followhere the original CLP de nition of [29, 28]. 4 De nition 2 (CLP programs) [29] Let h ; i be a S-sorted signature withdetermined by C and B . A h ; i-clause is formula of the formH c 2 B1; : : : ; Bn:where n 0, c is a ( nite) h ; Ci-constraint, H (the head) and B1; : : : ; Bn (thebody) are h ; Bi-atoms with n 0. If n = 0 the formula is called unit clause. Ah ; i-program is a nite set of h ; i-clauses. A goal is a conjunction c2B1; : : : ; Bnwhere c and the Bi's are de ned as before.De nition 3 (Constrained atom) For h ; i de ned as before, a h ; i-constrainedatom is an object of the form p( ~X) c, where c is possibly in nite set of h ; Ci-constraints, p( ~X) is a h ; Bi-atom and ~X are distinct variables.Note that, di erently from CLP unit clauses, a constrained atom can contain anin nitary constraint. The reason for this assumption will be made clear in section4.1 (see discussion after proposition 33). In the CLP(X ) framework, X stands fora speci c constraint domain on which the computation is performed. The notion ofstructure gives the semantic interpretation of such a domain and is the key element inthe algebraic semantics. The following is essentially the usual de nition of structurefor a many sorted rst order language (note that only the predicate symbols used forconstraints are interpreted).De nition 4 (Structure) [29] Given an S-sorted signature h ; i with deter-mined by C and B , a structure Dh ; i consists of1. a collection of non-empty sets Ds, where s ranges over the sorts in S,2. an assignment to each n-ary function symbol f 2 s1;s2;:::;sn;s 2 of a functionDs1 : : : Dsn ! Ds;3. an assignment to each n-ary predicate symbol p 2 s1;s2;:::;sn 2 C , apart from= (which is interpreted as equality) of a subset of Ds1 : : : Dsn .A Dh ; i-valuation for a h ; i-expression is a collection of mappings # = f#sgs2S#s : Vs ! Ds, where Vs is the set of the variables of sort s. # can be lifted homo-morphically to a (unique) collection of functions still called valuations and denotedby # = f#sgs2S , #s : ( [ V )s ! Ds.We assume that for any s, Ds contains at least two elements. h ; i-programs, h ; i-formulas, h ; Ci-constraints and h ; i-constrained atoms will be called programs,formulas, constraints and constrained atoms respectively. Moreover Dh ; i will bedenoted by D. The notion of D-valuation is extended in the obvious way to termsand formulas. The application of a valuation # to a tuple of terms ~t is denoted by ~t#.If A = p(~t) is an atom and # is a D-valuation such that ~t# = ~d holds, then A# denotesthe element p( ~d). This notation is extended in the obvious way to conjunctions.Given a formula , D j= means that is true under the interpretation providedby D. Moreover, given a constraint c and a valuation # for the variables in c, we usealso the notation D j= c# to denote that c# is true in D. If C is a possibly in nite setof atomic constraints, D j= C# holds i , for any c in C, D j= c# holds. The notion ofsolvability (i.e. satis ability) is the standard one.5 De nition 5 (Solvability) A (set of) constraint(s) c is D-solvable i there existsa D-valuation # such that D j= c# (i.e. i D j= 9:c holds). # is called a D-solution ofc. A constrained atom p( ~X) c is D-solvable i c is D-solvable.The structures considered in CLP are \solution compact" [29, 28]. Solution com-pactness consists of two conditions on the structure. Roughly speaking, the rst onerequires that any element d of the domain of D can be de ned as the unique solu-tion of a possibly in nite set of constraints. The second one requires that for everyconstraint c there exists a collection of constraints whose disjunction describes thecomplement of c. An extensive discussion and some results on solution compactnesscan be found in [36]. We give below the formal de nitions as given in [36] (which areessentially the same of the original de nition in [29], modulo a restriction to unaryconstraints). A structure D is solution compact i it satis es the following properties.SC1 For any sort s and for any d 2 Ds, there exists a possibly in nite set of con-straints fci(x)gi2I with a single free variable x such that for each D-solution #of fci(x)gi2I , x# = d. In symbols8s 8d 2 Ds; 9fci(x)gi2I s:t: D j= 8x:x = d$ î2I ci(x):SC2 For every tuple of elements ~d 2 D1 : : : Dk and for every constraint c thereexists a constraint c0 such D j= c0( ~d), and D j= :c( ~d) i D j= :9~xc(~x) ^ c0(~x).In symbols 8 ~d 8c 9c0 s:t: D j= c0( ~d) ^ (c( ~d)$ 9~x c(~x) ^ c0(~x)):The formulation of SC2 is equivalent ([36]) to the previously discussed condition8c 9fci(~x)gi2I s:t: D j= 8x::c(~x)$ _i2I ci(~x):As discussed in [29, 36] the main reason for requiring solution compactness (inparticular SC2) is to have a clear relation between nite failures and the algebraicimmediate consequences operator. Even if most constraint domains satisfy SC1 andSC2, it can be debatable if such assumptions are really necessary for de ning con-straint languages. Indeed, it is worth noting that other frameworks for logic constraintlanguages have been de ned [27] without any assumption on solution compactness 2.Almost all the results that we will give in the following hold also for structureswhich are not solution compact and could easily be extended to the framework of [27].In particular, since we are not concerned with negation, no result will assume conditionSC2. Condition SC1 is needed only to be able to have a syntactic representation (interms of our -interpretations) of the D-interpretations used in [29, 28] (de nitions15 and 16). Therefore, the only results which assume condition SC1 are theorem 43,theorem 58 and the related lemmata (essentially those which use de nition 16).In this paper we will consider only an \algebraic" formalization of the semantics,i.e. all our constructions are based on a h ; i-structure D and on the notion of D-solvability. Equivalent logical de nitions can be given by using the following notion.2In the survey [30] SC1 is not any more assumed as a condition for the CLP scheme.6 De nition 6 [Correspondence] [29] Let T be a ( rst order) h ; i-theory and D bea h ; i-structure. We say that T and D correspond if(i) D is a model of T and(ii) for every h ; i-constraint c, D j= 9c implies T j= 9c.If the theory T corresponds to D according to previous de nition, instead ofchecking the D-solvability of a constraint c we can check if 9c can be derived from theaxioms of T . For example, Clark's Equational Theory (CET )[9] corresponds to thestructure H consisting of the Herbrand universe with the standard interpretation forterms and where =, which is the only predicate symbol for constraints, is interpretedas identity.Logical formulations of the semantics for CLP can then be obtained by using acorresponding T instead than D. Indeed, several of the semantics de ned in [29] wereexpressed in logical form. The logical de nitions of our semantics and the equivalenceresults are contained in [19].3 -interpretations and -modelsIn this section we introduce the notion of -model and we show its relation to thestandard notion of D-model as introduced in [29].Since the structure D is the intended domain of computation for CLP, interpreta-tions for CLP programs are based on D. All the following de nitions are then relatedto a given D (and therefore to a given h ; i).Before giving the standard de nitions ofD-base andD-model we need the following[ ] operator on constrained atoms which returns the set of \domain instances".De nition 7 (Domain instances) Let p( ~X) c be a constrained atom. Thenwe de ne[p( ~X) c] = fp( ~X)# j # is a D-solution of cg:This de nition can be extended to a set S of constrained atoms in the obvious wayby de ning [S] =SA2S[A].De nition 8 (D-base) [29] Let us consider a given signature h ; i (where isdetermined by C and B) and a given structure Dh ; i. The Dh ; i-base (D-basefor short) BD is de ned as followsBD = fp( ~d) j p 2 B has arity s1; : : : ; sn, and ~d 2 Ds1 : : : DsngDe nition 9 (D-interpretation and D-model) [29] A D-interpretation is anysubset of the D-base. The set of all the D-interpretations is denoted by ID.A constrained atom p( ~X) c is true in the D-interpretation I i [p( ~X) c] I .A clause H c2B1; : : : ; Bn is true in I i for each D-valuation # such that # isa D-solution of c, fB1#; : : : ; Bn#g I implies H# 2 I . A D-interpretation I is aD-model of a program P i any clause of P is true in I .Our notion of interpretation is based on constrained atoms. We rst need thefollowing.7 De nition 10 Let A be the set of constrained atoms. We de ne the relation v onA as follows p( ~X) c1 v p( ~X) c2 i [p( ~X) c1] [p( ~X) c2]:Moreover for a1; a2 2 A we de ne a1 ' a2 i a1 v a2 and a2 v a1.The equivalence ' is induced by a preorder on constrained atoms which representsthe notion of \being more constrained". Note that, by de nition, (p( ~X) c1) '(p( ~X) c2) i D j= 9 ~Xc1 $ 9 ~Xc2. In the following we will then use equivalentlyboth the notations.The proof of the following lemma is straightforward.Lemma 11 The relation v is a preorder and the relation ' is an equivalence.Using ' to abstract from purely syntactical di erences among constrained atoms,we de ne the semantic domain as follows.De nition 12 ( -base) Let A be the set of all the Dh ; i-solvable constrainedatoms. The -base of interpretations B is the quotient set of A w.r.t. the equivalencerelation '. The ordering induced by v on B will still be denoted by v.De nition 13 ( -interpretation) A -interpretation is any subset of B. The setof all the -interpretations is denoted by I.For the sake of simplicity A will represent the equivalence class of the constrainedatom A and, conversely, any B 2 A=' will be considered also as a constrained atomobtained by selecting any (arbitrary) representative element in B. It is easy to verifythat all our de nitions are independent from the choice of such an element.According to the previous de nition, if I is a -interpretation, then [I ] is a D-interpretation. Therefore we can de ne the notion of truth in -interpretations andof -models in terms of the standard notions as follows.De nition 14 ( -models) Let I be a -interpretation. A clause c is true in I i cis true in [I ]. I is a -model of a program P if all the clauses of P are true in I .If the structure D is solution compact the concepts of D-interpretation and D-model can be regarded as particular cases of the notions of -interpretation and-model. Let us rst de ne what it means to be \ground" for a constrained atom.De nition 15 A constrained atom p( ~X) c is D-ground i c de nes a uniqueelement ~d in the structure, i.e. i [p( ~X) c]=fp( ~d)g. Moreover we de neBG = fp( ~X) c 2 B j p( ~X) c is D-ground gIf the structure D satis es condition SC1 of solution compactness (see section2), we can uniquely represent each \domain instance" p( ~d) by a constrained atomp( ~X) c (representing an equivalence class) such that the solutions of the (possiblyin nite) set of constraints c uniquely de ne the elements ~d of the domainD. Therefore,there exists a one to one correspondence between the D-base BD (de nition 8) andBG B, which can be extended to a bijection between D-interpretations and those-interpretations which are subsets of BG. A D-interpretation I can then equivalentlybe considered as the -interpretation (I). Formally we have the following.8 De nition 16 Let D be a structure such that condition SC1 of solution compactnessholds. We de ne : BD ! BG as (p( ~d)) = p( ~X) c such that [p( ~X) c] = fp( ~d)g.Moreover : ID ! }(BG) is de ned as (I) = f (p( ~d)) j p( ~d) 2 Ig.Lemma 17 The functions and of the above de nition are well de ned and arebijections.Proof Since D satis es condition SC1, for any p( ~d) 2 BD there exists p( ~X) c 2BG such that [p( ~X) c] = fp( ~d)g. Moreover if there exists p( ~X) c0 such that[p( ~X) c0] = fp( ~d)g then p( ~X) c0 ' p( ~X) c. Since BG contains ' equivalenceclasses this implies that is well de ned. is obviously bijective.: ID ! }(BG) is well de ned (because is well de ned) and is surjective byde nition of }(BG). Moreover, if (I) = (J) and I 6= J then there exist A 2 I ,B 2 J such that A 6= B and (A) = (B). This is a contradiction, since is abijection. Therefore the thesis holds.Note that, by de nition, is the inverse of [ ]. Our notion of -model is de ned interms of the standard de nition of truth. Therefore, from the model-theoretic pointof view, a D-model M is equivalent to the model (M).Lemma 18 Let I be a D-interpretation, J be a -interpretation and c be a clause.Then c is true in I i c is true in (I). Moreover c is true in J i c is true in [J ].Proof Since [ (I)] = I , the thesis follows from de nition 14.A parallel with the logic programming case can clarify the picture. Pure logicprogramming can be obtained from the general CLP framework by considering thestructure H( ; f=g [ B) where = is the only predicate symbol for constraints, theonly H-domain is the Herbrand universe over a one-sorted signature and = isinterpreted as syntactic equality over the domain. In the following we will refer to sucha structure as H. The standard semantics for logic programs de nes models as setsof ground atoms and this is exactly what is obtained by H-models de ned accordingto [29]. The new Herbrand base de ned in [17] contains non-ground atoms in themodels, where a non-ground atom stands for an implicit de nition of the (possiblyin nite) set of all its ground instances. This mechanism is generalized in the CLPcase by allowing constrained atoms in the -base, each constrained atom p( ~X) cdescribing the set of elements p( ~X)# where # is any D-solution for the constraintc. In order to abstract from the particular syntactic representation of atoms, in thelogic programming case the new Herbrand base is de ned modulo variance. In factH has the important property of the existence of a unique (up to variable renaming)canonical form of H-constraints which allows us to syntactically identify H-equivalentconstraints, namely the solved form of [33]. This property allows us to compute on theHerbrand universe in a purely syntactic way by using uni cation theory. In particular,the uni cation algorithm, which computes an idempotent mgu, can be considered theconstraint solver which decides the solvability of constraints and, if possible, returnsthe canonical form.In the general CLP case we have to use an explicit semantic de nition since theexistence of a syntactic way for characterizing semantically equivalent constraintsdepends on the particular constraint system. For example, results analogous to the9 H case hold for the HII( ; f=; 6=g [ B) structure, which essentially correspondsto PROLOG-II [11], where the domain is the in nitary Herbrand universe and theconstraints are equations (s = t) and disequations (s 6= t). If is in nite, results in[32, 12] show the existence of a normal form for sets of equations and disequationsand give an algorithm for computing it. Canonical forms exist on arithmetic domainsas well. For example, a canonical form for generalized linear constraints (an extendedclass of linear arithmetic constraints) has been given in [34].It is worth noting that, in the case of the H structure, our de nitions boil downto those considered in the s-semantics construction [17], since the following lemma 19is a straightforward consequence of the results in [33].Lemma 19 Let A1 : p( ~X) e1 and A2 : p( ~Y ) e2 be two H-constrained atoms.Then if the Herbrand universe is not trivial the following propositions hold1. [A1] = [A2] = ; i ei is not uni able, i = 1; 2,2. [A1] = [A2] 6= ; i p( ~X)#1 and p( ~X)#2 are variant, where #i is an idempotentmgu of the set of equations ei for i = 1; 2.4 Derivation rule, observables and operational se-manticsIn this section we rst consider the CLP derivation rule as de ned in [29, 28] andwe de ne two program equivalences based on di erent observables. Then we give thede nitions of various operational (success set) semantics and we show their relationsto the previously de ned equivalences. As usual, all the de nitions are parametricwrt a given structure D. We will often omit this parameter to simplify the notation.The operational semantics of (logic) programs can be speci ed by means of a setof inference rules which specify how derivations are made and by de ning which arethe \observables" we are interested in. The CLP inference rule is a straightforwardmodi ed version of the usual SLD derivation rule for pure logic programs which takesinto account the fact that the derivation is performed over a generic structure Drather than over the Herbrand universe. Therefore uni cation is replaced by checkingthe satis ability of constraints.The following de nitions use a \parallel" selection rule, where all the atoms of theresolvent are evaluated in a single derivation step. As far as successful derivations areconsidered, such a de nition can be easily proved to be equivalent to the more usualone which selects a single atom in each resolvent.De nition 20 (Derivation step) [29] A derivation step for the goalG : c2p(~t1); : : : ; p(~tn) in the program P results in a goal of the form ~c2 ~B1; : : : ; ~Bn;and is denoted byc2p(~t1); : : : ; p(~tn) P; ~c2 ~B1; : : : ; ~Bn;if there exist n variants of clauses in P ,p(~li) ci2 ~Bi; i = 1; : : : ; n, with no variablesin common with G and with each other, such that ~c is the D-solvable constraintc n̂i=1(~ti =~li ^ ci):10 De nition 21 (Derivation) [29] A derivation of a goal G in a program P is anite or in nite sequence of goals such that every goal, apart from G, is obtainedfrom the previous one by means of a derivation step. A successful derivation of a goalG is a nite sequence whose last element is a goal of the form (c2:). In this case, if~X = V ar(G) then 9 ~Xc is called the answer constraint 3.In the following we will denote by P; both a single derivation step and a derivation.Given the derivation rule, we can be interested in di erent observable propertiessuch as successful derivations, answer constraints, nite failures, etc. A given choiceof the observableX induces an \observational" equivalence X on programs. NamelyP1 X P2 i P1 and P2 are observationally indistinguishable according to X . Forexample, if s denotes successful derivations, P1 s P2 i for any goal G, G has asuccessful derivation in P1 i it has a successful derivation in P2.When composition of programs is taken into account, for a given observable prop-erty we obtain di erent congruences depending on which kind of program compositionwe consider. Given an observable X and a program composition operator , the in-duced congruence ( ;X) is de ned as follows. P1 ( ;X) P2 i for any program Q,P1 Q X P2 Q, i.e. i P1 and P2 are observationally indistinguishable under anypossible context allowed by the composition operator . X can be seen as the par-ticular case of ( ;X) where does not allow any composition. A semantics S(P ) iscorrect wrt ( ;X), if S(P1) = S(P2) implies P1 ( ;X) P2. Moreover S(P ) is fullyabstract wrt ( ;X) when also the converse of the previous implication holds.Let us now de ne two equivalences for constraint logic programs induced by dif-ferent observables. In the next section we will de ne the formal operational semanticswhich are correct and fully abstract wrt these equivalences. The rst equivalence isobtained by considering successful derivations only, no matter what is the computedconstraint. As discussed in the next subsection, it is de ned in terms of extendedgoals possibly containing in nite constraints (recall that standard goals contains -nite constraints only). The second one, which takes into account the computed answerconstraints, is the most natural to be de ned since we are interested in the result ofthe computation. A congruence ( ;X) where is program union will be consideredin section 7.De nition 22 (Observational equivalences) Let P1; P2 be programs, G be agoal with ~X = V ar(G) and D be a structure. Moreover let us assume that G!is a goal which contains in nitary constraints, i.e. G! : c2A1; : : : ; An where c is apossibly in nite conjunction of constraints. Then we de ne1. P1 s P2 i , for any G!, there exists a derivation G! P1; c12: i there exists aderivation G! P2; c22:,2. P1 ac P2 i , for any G and for any i; j 2 [1; 2], if there exists a derivation G Pi;ci2:, then there exists a derivation G Pj; cj2: such that D j= 9 ~Xci $ 9 ~Xcj .We will show in the next subsection the relations among the above equivalences.3In the original de nitions [29, 28] the answer constraint was c (without quanti cation). Wefollow here the more recent terminology used in the survey [30].11 4.1 Operational semanticsWe rst consider the operational semantics O2 which was de ned in [29] and proved tobe equivalent to the set of atomic logical consequences in D-models. Such a semanticsis not correct wrt ac, i.e. it is too weak to characterize the operational behavior ofprograms in terms of answer constraints. Therefore we de ne the semantics O3 whichis correct and fully abstract wrt ac. We nally consider the \ground" semantics O1which is correct and fully abstract wrt s.De nition 23 (Operational semantics O2) [29] Let P be a program. Then wede neO2(P ) = fp( ~X) c 2 B j there exists a derivation c2p( ~X) P; c02:such that c is nite and p( ~X) c ' p( ~X) c0 g:De nition 23 in the logic programming case is the same as the C-semantics [17]which characterizes the set of atomic logical consequences of P . A similar result holdsalso for the CLP case (see theorem 65 of section 6).The semantics O2(P ) does not characterize the operational behavior of the pro-gram, since it is not correct wrt ac. Indeed, as shown by the following example,there are programs which compute di erent answer constraints for the same goal andwhich are identi ed by O2(P ).Example 24 Let us consider the h ; i-programsQ1 = f q(X) true2: gQ2 = f q(X) true2:q(X) c2: gwhere c is any satis able constraint on the variable X di erent from true. ThenO2(Q1) = O2(Q2) = fq(X) c0 2 B j c0 is nite g. However, since the goaltrue2q(X) computes the answer constraint c in Q2 only, Q1 ac Q2 does not hold.To obtain a semantics correct wrt ac we give then the following de nition.De nition 25 (Operational semantics O3) Let P be a program. Then we de neO3(P ) = fp( ~X) c 2 B j there exists a derivation true2p( ~X) P; c2: g:Note that example 24 is not a counterexample to the correctness of O3(P ). Infact, O3(Q1) 6= O3(Q2) since O3(Q1)=fq(X) trueg, while O3(Q2)=fq(X) true; q(X) cg.Let us show an example of the O3 semantics of a CLP (<) program where < isthe constraint domain of arithmetic over the real numbers [31] 4.4The signature for < contains the constant symbols 0 and 1, the binary function symbols + and ,and the binary predicate symbols +; <; for constraints which are interpreted on the real numbersas usual. If we omit the symbol from the previous signature, we obtain the constraint domainis the principal, T is the mortgage lifetime in months, I is the annual percentageinterest rate, R is the monthly repayment and B is the outstanding balance.P = f mortgage(P; T; I; R;B) T = 1; B +R = P (1 + I=1200):mortgage(P; T; I; R;B) T > 12mortgage(P (1 + I=1200) R; T 1; I; R;B): gProgram P can be queried in several di erent ways. For example the goaltrue2 mortgage(100000,360,12,R,0) computes the answer constraint R = 1028:61while the goal true 2 mortgage(P,120,12,R,B) has answer constraint P = 0:303 B+69:7 R. The O3(P;R) semantics of program P is the following setf mortgage(P; T; I; R;B) T = 1; B +R = P (1 + I=1200);mortgage(P; T; I; R;B) T = 2; B +R = P (1 + I=1200)2+R (1 + I=1200)mortgage(P; T; I; R;B) T = 3; B +R = P (1 + I=1200)3+R (1 + I=1200)2 R (1 + I=1200)...gThe following theorem 28 shows that any answer constraint for any goal G com-puted in the program P can be obtained by \executing" G in the model O3(P ). Werst need one lemma which states the \AND-compositionality" and a `lifting" prop-erty of the answer constraints, i.e. the answer constraint of a goal G can be obtainedfrom the answer constraints of the most general version of the atoms in G.Lemma 27 (AND-compositionality and lifting) Let P be a program, G :(c02p1(~t1); : : : ;pn(~tn)) be a goal and let ~Y = V ar(G). If there exists a derivationG P; cans2: then(i) for any i 2 [1; n] there exists a successful derivation true2pi( ~Xi) P; ci2: whichshare no variables with G and with each other,(ii) the constraintc0Vni=1(ci ^ ~Xi = ~ti), denoted by c, is D-satis able,(iii) D j= 9 ~Y cans $ 9 ~Y c.Conversely, if (i) and (ii) above hold, then there exists a derivation G P; cans2:such that (iii) holds.Proof This lemma is a particular case of lemma 102 which is proved in the appendix.Theorem 28 Let P be a program, G :(c02p1(~t1); : : : ;pn(~tn)) be a goal and let~Y = V ar(G). If there exists a derivation G P; cans2:, then(i) there exists n constrained atoms pi( ~Xi) ci 2 O3(P ), i 2 [1; n], which share novariables with G and with each other,(ii) the constraintc0Vni=1(ci ^ ~Xi = ~ti), denoted by c, is D-satis able,13 (iii) D j= 9 ~Y cans $ 9 ~Y c.Conversely, if (i) and (ii) above hold, then there exists a derivation G P; cans2: suchthat (iii) holds.Proof The theorem follows in a straightforward way from lemma 27 by observingthat, by de nition of O3, if there exists a derivation true2p( ~X) P; c2: then (theequivalence class of) p( ~X) c 2 O3(P ) and, conversely, if p( ~X) c0 2 O3(P ) thenthere exists a derivation true2p( ~X) P; c2: such that D j= 9 ~Xc0 $ 9 ~Xc.Note that theorem 28 does not hold if we consider O2. A simple counterexamplecan be obtained by considering the predicate q(X) in the program Q1 of example 24.As a consequence of the previous result we obtain corollary 29 which shows thatthe semantics O3 is correct and fully abstract wrt the observable equivalence acinduced by answer constraints. In other words, O3 correctly models the operationalbehavior of programs, considering answer constraints as observable, and it is the bestpossible in the sense that it contains the least amount of information needed to becorrect.Corollary 29 (Correctness and full abstraction) Let P1; P2 be programs. ThenP1 ac P2 i O3(P1) = O3(P2):Proof The if part is straightforward by theorem 28. For the only if part, assumethat P1 ac P2 and p( ~X) c 2 O3(P1). Then there exists a successful derivationof true2p( ~X) in P1 with answer constraint c0 such that D j= 9 ~Xc0 $ 9 ~Xc. SinceP1 ac P2, there exists a successful derivation of true2p( ~X) in P2 with answer con-straint c00 such that D j= 9 ~Xc0 $ 9 ~Xc00. Therefore O3(P1) O3(P2). Analogouslyfor the other implication.Let us nally consider the s equivalence. The semantics that we have consideredare too rich if we are interested in successful derivations only. Namely neither O2 norO3 are fully abstract wrt s. We will then consider a di erent semantics which caneasily be obtained from the previously de ned ones. We rst give a proposition.Proposition 30 Let P be a program. Then [O2(P )] = [O3(P )].Proof Let p( ~d) 2 [O2(P )]. Then, by de nition, there exists a derivation c2p( ~X) P;c12: such thatD j= 9 ~Xc$ 9 ~Xc1 and p( ~d) = p( ~X)# holds, where # is a solution of c.By lemma 27 there exists a derivation true2p( ~X) P; c22: such that D j= 9 ~Xc^c2 $9 ~Xc1 . Therefore the valuation # can be extended to a solution #0 of c[ c2 such thatp( ~X)# = p( ~X)#0 holds. Since, by de nition of O3(P ), p( ~X) c2 2 O3(P ) and #0 isa solution of c2, p( ~d) 2 O3(P ).Conversely, if p( ~d) 2 [O3(P )] then there exists a derivation true2p( ~X) P; c22: suchthat p( ~d) = p( ~X)# holds where # is a solution of c2. Since c2 ^ c2 is equivalentto c2 and satis able, by lemma 27 there exists a derivation c22p( ~X) P;c022: withD j= 9 ~Xc2 $ 9 ~Xc02 and this completes the proof.14 We can now de ne the third operational semantics.De nition 31 Let P be a program. The success set semantics O1(P ) is de ned asfollowsO1(P ) = [O3(P )]:Note that in the pure logic programming caseO1 is the standard ground success setsemantics equivalent to the least Herbrand model. In the case of CLP it is not verynatural to consider the \ground" success set since derivations compute constraintsand, instead of grounding substitutions, we should consider D-grounding constraints(according to de nition 15). A semantics equivalent to O1 was de ned in [29] by axpoint construction (see next section) and related to O2 by a (weak) equivalenceresult.As in the case of pure logic programming, the O1(P ) semantics correctly capturesthe \successful derivations" observable. The following proposition shows that O1(P )is correct and fully abstract wrt s.Lemma 32 Let P be a program and let D be a structure such that condition SC1of solution compactness holds. Then p( ~d) 2 O1(P ) i , for c such that [p(~x) c] =fp( ~d)g, c2p( ~X) has a successful derivation in P .Proof ()). Assume p( ~d) 2 O1(P ). By de nition 31 there exists p(~x) c1 2 O2(P )such that p( ~d) 2 [p(~x) c1]. By de nition of O2, c12p(~x) has a successful derivationD in P with an answer constraint c2 such that [p(~x) c1] = [p(~x) c2]. Thereforep( ~d) 2 [p(~x) c2]. Since D is solution compact (in particular it satis es SC1),there exists a (possibly in nite) c such that [p(~x) c] = fp( ~d)g. The fact thatp( ~d) 2 [p(~x) c2], since c2 is the answer constraint of the derivation D, implies thatc^ d is satis able for any constraint d introduced in D. Therefore (by using the sameclauses used in D) c2p(~x) has a successful derivation in P .((). Assume that [p(~x) c] = fp( ~d)g and c2p( ~X) has a successful derivation D inP with answer constraint c2 = (c1^c), where c1 contains the constraints accumulatedby the clauses used in D. Since c is \grounding", for any d such that c^d is satis ablep( ~d) 2 [p(~x) c; d]. Therefore p( ~d) 2 [p(~x) c1; c] which impliesp( ~d) 2 [p(~x) c1]:(1)Moreover, by de nition of derivation and of c1, the goal c12p( ~X) has a successfulderivation D in P with answer constraint c3 such that [p(~x) c1] = [p(~x) c3].This, together with (1), de nition 23, de nition 31 and proposition 30 completes theproof.Proposition 33 (Correctness and full abstraction) Let P1; P2 be programs andlet D be a structure such that condition SC1 of solution compactness holds. ThenP1 s P2 i O1(P1) = O1(P2).Proof ()) Straightforward by de nition 22 and lemma 32.(() We prove the contrapositive. Assume P1 6 s P2. Then there exists a goalG : (c02A1; : : : ; An) which has a successful derivation D in P1, say with answerconstraint c, and which has no successful derivation in P2. Let ~Y = V ar(G) and15 assume p( ~d) 2 [p( ~Y ) c]. Since condition SC1 holds, there exists a constraint dsuch that fp( ~d)g = [p( ~Y ) d ^ c]. The facts that p( ~d) 2 [p( ~Y ) c], d ^ c isgrounding for p( ~Y ) and that c is an answer constraint for the derivation D implythat, by using the same clauses used in D, c^ d2Ai has a successful derivation in P1for any i 2 [1; n]. On the other hand, since G has no successful derivation in P2 andc0 is contained in c ^ d, clearly c ^ d2A1; : : : ; An has no successful derivation in P2.Since c^ d is grounding for the variables in A1; : : : ; An this implies that there exist aj 2 [1; n] such that c^ d2Aj has no successful derivation in P2. Therefore, by lemma32, O1(P1) 6= O1(P2) and this completes the proof.One could wonder whether the previous proposition holds when considering sde ned by using only \standard" goals, i.e. goals containing nite constraints only.We note that this is not the case when the structure is not solution compact. Indeed,let us consider the following (arti cial) constraint domain which satis es SC1 and notSC2.Example 34 [30] Let R be the constraint domain obtained fromRLin (linear arith-metic over the reals) by adding an extra unary predicate np. np(X) holds in (thestructure of) < i X 6= . Since :np(X) i X = , SC2 can be satis ed i thereexists a constraint c such that < j= X = $ c(X). Since is irrational no such cexists and therefore the structure does not satisfy SC2. Note that SC1 is satis ed.Let us now consider the programs P = fp(X) np(X)2:g and Q = fp(X)true2:g on the structure < of the previous example. Clearly O1(P ) 6= O1(Q) sincep( ) 2 O1(Q) n O1(P ). However, any goal c2p(X), with c nite, has a successfulderivation in P i it has a successful derivation in Q. In fact, if c is nite thenc^ np(X) is always satis able. We conjecture that if both SC1 and SC2 are satis edby D, then the previous proposition holds also when the de nition of s considersnite constraints only.The following proposition shows the relative strength of the two equivalences.Proposition 35 Let P1; P2 be programs. If P1 ac P2 then P1 s P2. The reversedoes not generally hold.Proof If P1 ac P2 then, by corollary 29, O3(P1) = O3(P2) and, by de nition 31,O1(P1) = O1(P2). Therefore the implication follows by proposition 33. A counterex-ample for the reverse is given in example 36.The following example shows that the equivalence s is strictly coarser than ac.Example 36 Let us consider the H( ; f=g [ B)-programsW1 = f q(X) true2: gW2 = f q(X) X = a2:q(X) X = b2: gwhere = fa; bg. Then W1 s W2 since O1(W1) = O1(W2) = fq(X) X =a; q(X) X = bg. However W1 6 ac W2. The two programs have di erent compu-tational behaviors since the goal true2q(X) computes the answer constraints X = aand X = b in W2 only.16 5 Fixpoint semanticsWe give in this section a xpoint characterization of all the semantics we have con-sidered. It is worth noting that, even if the success set semantics given in [29] wasO2, the algebraic xpoint semantics of [29] characterized O1 (a xpoint de nition wasgiven also for a logical version of the O3 semantics, see [19]).The semantics are de ned by using three di erent immediate consequence opera-tors based on the structure D.The rst operator we consider is T 1P which was originally de ned in [29] on D-interpretations. Recall that the D-base BD used in [29] is related to our interpretationbase by the equation BD = [B] and that a D-interpretation is any subset of BD.De nition 37 (T 1P operator) [29] Let P be a program and let J [B].T 1P (J) = fp( ~d) 2 BD j 9 p(~t) c2B1; : : : ; Bn 2 P;9 an D-valuation # such thatD j= ~t# = ~d; D j= c# and fB1#; : : : ; Bn#g J g:The usual properties of the mapping T 1P are proved in [29]. Namely T 1P is con-tinuous on the cpo (ID; ), where ID=fI jI BDg and there exists a least xpointlfp(T 1P ) = T 1P " !.De nition 38 (Fixpoint semantics F1(P )) [29] Let P be a program. Then thexpoint semantics F1(P ) of P is de ned as F1(P ) = T 1P " !:We want now to de ne an analogous of the T 1P operator using our semantic struc-tures ( -base and -interpretations). The functional T 1P maps from and into theD-base. By exploiting the isomorphism : BD ! BG introduced in section 3, it isthen possible to de ne the corresponding functional T 10P , which maps from and intoBG.De nition 39 Let P be a program and let J BG. We de neT 10P (J) = f (p( ~d)) j p( ~d) 2 T 1P ([J ])g:Corollary 41 is a straightforward consequence of theorem 40 and gives the char-acterization of the equivalence between the operational semantics O1 and F1.Theorem 40 [29] Let P be a program. Then [O2(P )] = F1(P ).Corollary 41 (Equivalence) Let P be a program. Then O1(P ) = F1(P ).The properties of the operator T 10P are shown by the following lemma, whose proofis standard. The relation between the xpoints of the operators T 1P and T 10P are shownby proposition 43.Lemma 42 The mapping T 10P is continuous on the complete lattice (IP ; ). Thereexists a least xpoint lfp(T 10P ) of T 10P which is T 10P " !.Proposition 43 Let P be a program. Then F1(P ) = [T 10P " !].17 Proof Straightforward by de nition 39.We introduce now a di erent immediate consequence operator, which allows us tocharacterize the operational semantics O3.De nition 44 (T 3P operator) Let P be a program and let J B.T 3P (J) = f p( ~X) c 2 B j9 p(~t) c02p1( ~t1); : : : ; pn( ~tn) 2 P; renamed apart9 pi( ~Xi) ci 2 J; 1 i n renamed apartthe constraintc0Vni=1 ~Xi = ~ti ^ ci); denoted by c0;is D-solvable, nite and c is c0wedge ~X = ~t)g:The following lemma allows us to de ne a xpoint semantics using the T 3P operator.The proof is standard.Lemma 45 The mapping T 3P is continuous on the complete lattice (IP ; ). Thereexists a least xpoint lfp(T 3P ) of T 3P which is T 3P " !.De nition 46 (Fixpoint semantics F3(P )) Let P be a program. The xpointsemantics F3(P ) of P is de ned as F3(P ) = T 3P " !:Corollary 47 shows that we have the expected equivalence between the operationaland the xpoint semantics. The following result is a corollary of the more generaltheorem 90 and will be proved in section 7.Corollary 47 ( Equivalence) Let P be a program. Then O3(P ) = F3(P ).It is possible to give also a xpoint characterization of O2 by slightly modifying thede nition of T 3P . Indeed, the di erence between O2 and O3 is that the former containsall the (equivalence classes of) constrained atoms which are true in all the -modelsof the program (see next section), while the latter contains only those constrainedatoms which can be computed by the program. In other terms, O2 could equivalentlybe de ned by adding at each derivation step any constraint which is consistent withthose already computed. Therefore in order to capture O2, we have to modify T 3P byadding at each step any consistent constraint. Hence we have the following de nition.De nition 48 Let P be a program and let J B.T 2P (J) = f p( ~X) c 2 B j9 p(~t) c02p1( ~t1); : : : ; pn( ~tn) 2 P; renamed apart9 pi( ~Xi) ci 2 J; 1 i n; renamed apart; 9c s.t.c0 is the constraint c0 ^ cVni=1( ~Xi = ~ti ^ cic0 is D-solvable, nite and c is (c0 ^ ~X = ~t)g:The usual results hold for T 2P too, namely the continuity on the complete lattice(IP ; ) and the existence of the least xpoint lfp(T 2P )=T 2P " !. Hence we can de nea xpoint semantics F2(P ) = T 2P " ! which corresponds to the operational semanticsO2(P ). The equivalence between the success set and the xpoint semantics is statedby the following theorem, whose proof is analogous to that of corollary 47.Theorem 49 Let P be a program. Then O2(P ) = T 2P " !.18 6 The model-theoretic semanticsIn this section we discuss the various -interpretations introduced by the xpointand the operational semantics from the model-theoretic viewpoint. In particular wewill show that all the semantics we have considered so far are -models. Since weare concerned with the algebraic semantics, i.e. the semantics on the structure Dused as domain of computation, we consider logical consequence in D-models (D j=)as opposed to the standard notion of logical consequence j=. The two notions arerelated by theorem 51.De nition 50 Let P be a program and G be a constrained atom. We de ne P;D j=G i G is true in every D-model of P .Theorem 51 [29] Let D be a structure, T be a corresponding theory, P be a programand G be a goal. Then P;D j= 9 G i P [ T j= 9 G.It is easy to show that the intersection of a set of -models is not always a -model.Consider for example the H-clauses c1 : p(X) X = a2: and c2 : p(X) true2.Clearly I1 =fc1='g and I2 = fc2='g are -models of c1 while I1 \ I2 = ; is not.Therefore in general there exists no least -model with respect to set inclusion.In the following we will introduce a partial ordering and then a lattice structureon -interpretations which allows us to restore the model intersection property. Themodel theoretic semantics of a program P can then be de ned as the greatest lowerbound of the set of all the -models of P . Theorem 58 shows that this model theoreticsemantics de nition is the same of the usual one given in [29] in terms of D-models.De nition 52 (Ordering on -interpretations) We de ne a relation on I asfollows. Let I1; I2 2 I. ThenI1 I2 i 8A1 2 I19A2 2 I2 such that A1 v A2 andI1 I2 i (I1 I2) and (I2 I1 implies I1 I2).The previous de nition and the following lemmata extend to the CLP case resultsgiven in [18] for pure logic programs. The proof of lemma 53 can easily be obtainedfrom the proof of the analogous lemma in [18].Lemma 53 The relation is an ordering on I. Moreover (I; ) is a complete latticewhere ; is the bottom element and B is the top element.Lemma 54 LetM be the set of -models for a program P . Then glb(M) (accordingto ordering) is a -model of P .Proof Let A c2B1; : : : ; Bn be a clause of P . Let us consider an D-valuation# such that # is a D-solution of c and fB1#; : : : ; Bn#g [glb(M)]. By de nitionof glb, for any I 2 M , glb(M) I holds. By de nition of [ ] and by de nitionof , [glb(M)] [I ] and then fB1#; : : : ; Bn#g [I ]. Since A c2B1; : : : ; Bn istrue in I , fA#g [I ], by de nition 14. This implies (A#) I where is thebijection de ned in de nition 16. In fact, clearly (A#) I , where is de nedas in de nition 52. Moreover, if I(A#) then I(A#) since (A#) is D-ground (de nition 15) (recall that (A#) and elements in I are equivalence classes).Therefore, (A#) is a lower bound of M , and hence (A#) glb(M). This implies[ (A#)] = fA#g [glb(M)] and the thesis holds.19 De nition 55 (Model theoretic semantics) Let P be a program. Its model the-oretic semantics MP is de ned asMP = glbfN j N is a -model of P g:In the case of D-interpretations the ordering is set inclusion, and the followingresult in [29] shows that there exists the minimal D-model w.r.t. set inclusion.Theorem 56 [29] Let P be a program and let M be the set of all the D-models ofP . Then MD =Tm2M m is the least D-model of P w.r.t. set inclusion. MoreoverMD = F1(P ).MD is the CLP counterpart of the standard least Herbrand model for pure logicprograms. The following theorem shows that indeed MD is the \same" (up to thetransformation of de nition 16) of the least -model de ned according to theordering on -interpretations.Lemma 57 Let M be a -model of a program P . Then ([M ]) is a -model of Pand ([M ]) M .Proof Given a clause c, by lemma 18, c is true in M i c is true [M ]. By de nitionof , [ ([M ])] = [M ] and the rst part of the thesis holds. For the second part, letp( ~X) c 2 ([M ]). Then, by de nition of , [p( ~X) c] = fp( ~d)g [M ]. Byde nition of [ ], there exists a p( ~X) c0 2M with p( ~d) 2 [p( ~X) c0]. Then p( ~X)c v p( ~X) c0 and, by de nition 52, ([M ]) M . Let us assume now M ([M ]).By de nition of , if p( ~X) c0 2 M there exists p( ~X) c 2 ([M ]) such that[p( ~X) c0 2 M ] [p( ~X) c]. By de nition of ([M ]), [p( ~X) c] = fp( ~d)g andtherefore [p( ~X) c0] = [p( ~X) c], i.e. p( ~X) c ' p( ~X) c0 (de nition 10). Since-interpretations are de ned modulo ' (de nitions 12 and 13), M ([M ]). Since([M ]) M , M = ([M ]) and, by de nition 52, ([M ]) M and this completes theproof.Theorem 58 Let P be a program and MD be its least D-model. Then (MD) =MP .Proof Given any -model M of P , by lemma 57, ([M ]) M . By lemma 18[M ] is a D-model of P and MD is (by de nition) the least D-model (w.r.t. setinclusion) of P , MD [M ]. Then by de nition of , (MD) ([M ]) and hence(MD) ([M ]) M . Since M is any -model, we have (MD) MP . On theother hand MP (MD) by de nition of MP . Then by de nition of the thesisholds.As in the case of pure logic programming, the least model characterizes the set of\ground" D-logical consequences of the program and is equal to the \ground" xpointand operational semantics.Theorem 59 [29] Let p( ~d) 2 BD. Then P;D j= p( ~d) i p( ~d) 2 F1(P ) i p( ~d) 2 MD.The following lemmata are the CLP counterparts of a well known result for purelogic programs. They allow us to relate D-models and -models to the prexpointsof the various immediate consequence operators.20 Lemma 60 [29] A D-interpretation I is a D-model of a program P i T 1P (I) I .Lemma 61 Let P be a program and I be a -interpretation. If T 3P (I) I , then I isa -model of P .Proof Assume T 3P (I) I and let p(~t) c02p1( ~t1); : : : ; pn( ~tn) be a clause in P suchthat for a D-valuation # which is a D-solution of c0, fp1( ~t1)#; : : : ; pn( ~tn)#g [I ].Wehave to prove that p(~t)# 2 [I ].Note thatpi(~ti)# 2 [I ] i there exists pi( ~xi) ci 2 I such that the constraint ci issatis ed by the valuation # ( ~xi=~ti#). Moreover we can assume that all constrainedatoms pi( ~xi) ci share no variables. Then the substitution = # ( ~x1= ~t1#)( ~x2= ~t2#) : : : ( ~xn= ~tn#) solves the constraint c0 :(c0Vni=1( ~xi = ~ti ^ ci)). By de nitionof T 3P we have then [p(~x) c] 2 T 3P (I) I , where c is c0 ^ ~x = ~t. But obviouslyp(~t)# 2 [p(~x) c] [I ].Lemma 62 Let P be a program and I be a -interpretation. If T 2P (I) I , then I isa -model of P .Proof The proof is identical to the one of lemma 61 and is thus omitted.We can now prove that all the semantics that we have considered in the previoussections are -models.Theorem 63 (Fi(P ) are -models) Let P be a program. Then (F1(P )), F2(P )and F3(P ) are -models of P . Moreover, if p( ~X) c 2 Fi(P ), for i 2 [2; 3], thenp( ~X) c ' p( ~X) c0 where c0 is nite.Proof The thesis for F1(P ) follows from theorem 56 and lemma 57. By de nition,F3(P ) is a xpoint of T3(P ), and F2(P ) is a xpoint of T2(P ). Then by lemmata 61and 62 also F2(P ) and F3(P ) are -models of P . The second part of the thesis isstraightforward from de nitions of T 2P and T 3P .Proposition 64 shows the relations among the models. Note that the semanticsF3 which models answers constraints is not generally a minimal model.Proposition 64 Let P be a program. Then (F1(P )) F3(P ) F2(P ):Proof The rst relation follows from theorem 59 and theorem 58, since (F1(P )) =(MD) =MP andMP is the minimal -model w.r.t. the -ordering. For the secondrelation note that by de nition 52 ( ordering), if I1 I2 then I1 I2. Since bytheir de nitions F3(P ) F2(P ), we have F3(P ) F2(P ) which completes the proof.The following theorem shows how the model O2(P ) characterizes the set of theD-logical consequences of a program.Theorem 65 [29] Let P be a program and G : p( ~X) c be a constrained atom,where c is nite. Then P;D j= 9 G i G 2 O2(P ).Note that the previous theorem does not hold if we remove the hypothesis on theniteness of c. Indeed, since the constraints which appear in the clauses are nite,Oi(P ), i = 2; 3 are sets of (equivalence classes of) constrained atoms which can berepresented using nite constraints (lemma 63). Hence if P;D j= p( ~d) where p( ~d)is a limit element, we cannot have a syntactical representation for p( ~d) using niteconstraints only.21 7 Compositional semanticsIn this section we introduce a (operational and xpoint) semantics for CLP programswhich is compositional wrt the union of programs. This semantics is an easy liftingto the CLP case of the -semantics de ned in [7] for pure logic programs.Compositionality is an important feature for any semantics and, roughly speaking,consists in the possibility of obtaining the semantics of a compound syntactic constructin terms of the semantics of its components. In the case of (constraint) logic programs,the usual semantics are compositional wrt the conjunction of atoms (in the bodies ofthe clauses and in the goals) but are not compositional wrt the union of clauses. Sucha compositionality is a desirable property since it allows an incremental and modularde nition of the semantics, according to the incremental construction of programs.Each time a new chunk of program is added, instead of de ning the semantics ofthe whole program from scratch, we can compose the semantics of the new pieceof program with the semantics of the old one. This is particularly relevant from apractical point of view since it provides the semantic basis to develop tools for modularanalysis and veri cation of programs. In fact, even if the program is not completelyspeci ed in all its components, often we would like to perform some analysis in anycase and we want to be able to reuse the results of this \partial" analysis. Moreover,modular techniques can be used to split large programs into small components, toreduce the size and the complexity of the analysis.All the semantics that we have considered in the previous sections are not com-positional wrt the union of programs. The following is a simple example for the caseof O3.Example 66 Let us consider the H-programsP1 = f q(X) true2p(X):p(X) X = a2: gP2 = f p(X) X = b2: gP3 = f q(X) X = a2:p(X) X = a2: gwhere = fa; bg. ThenO3(P1) = fq(X) X = a; p(X) X = agO3(P2) = fp(X) X = bgO3(P3) = fq(X) X = a; p(X) X = agThus the semantics O3 identi es P1 and P3. However O3(P1 [ P2) 6= O3(P2 [ P3)since q(X) X = b 2 O3(P1 [ P3) n O3(P2 [ P3).The semantics based on constrained atoms do not contain the functional infor-mation which is expressed implicitly by clauses and which is necessary to achieve[-compositionality. For example, the semantics of P1 does not contain any informa-tion on q which allows us to infer that q(X) X = b is in the semantics of P1 [ P2.Such an information is expressed by the clause q(X) true2p(X). Therefore, com-positionality w.r.t. union of programs can be obtained by choosing a semantic domainbased on clauses. This idea was rst introduced in [24] and then further studied in22 [8, 7] for the case of pure logic programs. In the following we show the application toCLP of this idea, essentially by lifting the de nitions in [7] to the realm of constraints.Other compositional semantics based on a functional de nition (e.g. the TP function)could be lifted from pure logic programs to CLP in a similar way.We start by formally introducing the notion of partially de ned program.De nition 67 ( -open program) [7] An -open program ( -program for short)is a (constraint) logic program P together with a set of predicate symbols. Apredicate symbol occurring in is considered to be only partially de ned in P .An -open program P can be composed with other programs which may furtherspecify the predicates in . A typical partially de ned program could be a programwhere the intensional de nitions are completely known while extensional de nitionsare only partially known and can be further speci ed. The composition that weconsider here is simply union, modi ed in order to take into account the \interface"described by the set . In the following Pred(E) denotes the set of predicate symbolswhich appear in the expression E.De nition 68 ( -union)[7] Let P1 be an 1-program and P2 be an 2-program. If1.1 [ 2 and2. (Pred(P1) \ Pred(P2)) ( 1 \ 2)then P1 [ P2 is the -open program P1 [ P2. Otherwise P1 [ P2 is not de ned.Because of their \modular" nature open programs should have a semantics com-positional wrt the [ operator. Moreover, we are interested here in a semantics whichcorrectly models answer constraints. The compositional semantics will then be de-ned as a modi ed version of the answer constraint semantics F3, obtained by usinga semantic domain which contains clauses.In order to abstract from the purely syntactical details, in the de nition of thesemantic domain we use an equivalence on CLP clauses which, by abuse of notation,is still denoted by '.De nition 69 Let cl1 : A1 c12B1;1; : : : ; B1;n, cl2 : A2 c22B2;1; : : : ; B2;nbe two clauses. Then cl1 ' cl2 i , for any i; j 2 [1; 2], for any D-solution # ofci there exists a D-solution of cj such that Ai# = Aj holds and the multisets(Bi;1; : : : ; Bi;n)# and (Bj;1; : : : ; Bj;n) are equal.If we represent a unit clause p(~t) c2 by the constrained atom p( ~X) c; ~X = ~t,' on unit clauses is exactly the equivalence of de nition 10. Moreover, since all theconstrained atoms arising in the F3 semantics contain nite constraints only, in thefollowing they will be considered as unit clauses.According to the previous de nition, the body of a clause is viewed as a multiset.Viewing bodies of clauses as sets rather than multisets would not allow us to modelcorrectly answer constraints. In fact, as shown by the following example, clauses whichhave the same set of atoms in the body can produce di erent answer constraints whencomposed with other clauses.23 Example 70 Let us consider the H-clausesc1 : p(X;Y ) true2q(X;Y ); q(X;Y ):c2 : p(X;Y ) true2q(X;Y ):and let P1 = fc1g and P2 = fc2g be -open programs with = fqg. If bodies ofclauses are viewed as sets, c1 and c2 could be considered equivalent. However, if weconsider the program Q = f q(X;Y ) Y = b2:q(X;Y ) X = a2: gthe goal p(X;Y ) in P1[Q computes the answer constraint fX = a; Y = bg, while thegoal p(X;Y ) in the program P2 [ Q can compute either fX = ag or fY = bg only.Note that c1 6' c2.To obtain compositionality wrt [ we need only the information given by theclauses which contain, in their bodies, atoms whose predicate symbols are in .Therefore the following.De nition 71 The interpretation base C, is the set of all the clauses (on the givenlanguage) of the form p( ~X) c2 ~B modulo '. Moreover given a set of predicatesymbols, we de neC = fA c2B1; : : : ; Bn 2 C j Pred(B1; : : : ; Bn) g:De nition 72 ( -Denotations) An -denotation I is any subset of C . The set ofall the -denotations is denoted by I .Remark 1In the following, as usual, we will denote the' equivalence class of a clause c by c itself.To simplify the notation, any (semantic) subset I of C will implicitly be considered alsoas a syntactic program, still denoted by I , obtained by choosing for each equivalenceclass c 2 I an arbitrary element in c as representative of c. Conversely, any set ofclauses P will be also considered as a subset of C. The semantic operators (such asthe immediate consequence operator) that we will use on subsets of C will be de nedin terms of their syntactic counterpart de ned on sets of clauses. It easy to verifythat they are well de ned (see proposition 81).We de ne now the operational semantics O (P ). Given a set of predicate symbolswe denote by Id the set of clausesfp( ~X) true2p( ~X) j p 2 g:De nition 73 ( -semantics for CLP) Let P be a program and be a set ofpredicate symbols. Moreover let P = P [ Id . Then we de neO (P ) = fp( ~X) c2B1; : : : ; Bn 2 C j there exists a derivationtrue2p( ~X) P; c2B1; : : : ; Bn gMoreover if P is an -open program, O (P ) is also -open.24 O (P ) is essentially the result of the partial evaluation of P , where derivationsterminate at open predicates (i.e. predicates in ). The set of clauses Id in theprevious de nition is used to delay the evaluation of open atoms. As shown by thefollowing proposition, the compositional semantics contains the answer constraintsemantics O3(P ). Moreover for = ;, i.e. when all the predicates are consideredcompletely de ned, the two de nitions are equivalent.Proposition 74 Let P be a program. Then for any set of predicate symbols ,O3(P ) = O;(P ). Moreover O;(P ) is the set of (equivalence classes of) all the unitclauses in O (P ).Proof Straightforward from de nitions 12, 25 and 73.Let us now show the compositionality result for the OOmega semantics. The proofof the following theorem is in the appendix.Theorem 75 (Compositionality) Let P1 be an 1-open program, P2 be an 2-open program and let P1 [ P2 be de ned. ThenO (O 1(P1) [ O 2(P2)) = O (P1 [ P2):Example 76 Let P1; P2 and P3 be the -open programs of example 66 where =fpg. ThenO (P1) = fp(X) X = a2:; q(X) X = a2:; q(X) true2p(X):gO (P2) = fp(X) X = b2:gO (P3) = fp(X) X = a2:; q(X) X = a2:gO (P1) allows us to compute the semantics of the composition P1 [ P2. In factO (P1 [ P2) = O (O (P1) [O (P2)). Note also that O (P3) 6= O (P1).As a consequence of the previous theorem, the O (P ) semantics is correct wrt thecongruence ( ;ac) induced on programs by the answer constraint observable and by[ composition (corollary 78). In other words, O (P ) contains all the informationnecessary to model the behaviour of P , in terms of answer constraints, compositionallywrt union of programs. To simplify the notation we will denote ( ;ac) by . Notethat, according to the following de nition, for = ;, is the equivalence ac ofde nition 22.De nition 77 Let P1; P2 be -open programs. Then P1P2 i for every -program Q such that Pi [ Q, i = 1; 2, is de ned, P1 [ Q ac P2 [ Q.Corollary 78 (Correctness) Let P; P1 be -open programs. Then(i) P O (P )(ii) if O (P ) = O (P1) then P P1.25 Proof (i) By de nition 77, corollary 29 and proposition 74 we haveP O (P ) i O;(P [ Q) = O;(O (P ) [ Q)(2)for any program Q such that P [ Q is de ned. Moreover for any such a Q, we haveO (P [ Q)= (by theorem 75)O (O (P ) [ O (Q))= (by de nition 73)O (O (O (P )) [ O (Q)) = (by theorem 75)O (O (P ) [ Q):By proposition 74 this implies O;(P [ Q) = O;(O (P ) [ Q). Therefore by 2 thethesis holds.(ii) Straightforward by i):7.1 Fixpoint semanticsIn this section we de ne a xpoint semantics F (P ) which is proved to be equivalentto O (P ). This can be achieved by de ning an immediate consequence operator T Pon the complete lattice (I ; ) of -denotations. F (P ) is the least xpoint of T P .The immediate consequences operator T P is strongly related to the derivation ruleused for CLP programs. Indeed we de ne it in terms of an unfolding rule. This leads toa concise proof of the equivalence between the operational (top-down) and the xpoint(bottom-up) semantics. Since T P models the computed answers compositionally, itcan be useful for modular bottom-up program analysis.De nition 79 (Unfolding) Let P and Q be programs. Then the unfolding of Pw.r.t. Q is de ned asunfP (Q) = f(p(~t) c2~L1; : : : ; ~Ln) j 9 p(~t)co2pi(~ti); : : : ;pn(~tn) 2 P;9pi(~li) ci2~Li 2 Q; i = 1; : : : ; nrenamed apart, s.t. the constraintc :(c0Vni=1(~ti =~li ^ ci))is D-satis able gDe nition 80 (T P operator) Let p be an -open program and let I be an -denotation. Then we de ne T P : }(C)! }(C) asT P (I) = unfP (I [ Id )According to the previous remark, unfP (Q) denotes also an operator }(C)! }(C)and therefore the de nition of T P is correct. The following proposition 81 shows thatunfP (Q) (and hence T P ) on }(C) is well de ned (i.e. the result does not depend onthe choice of the representative element). Moreover, note that for = ;, T P is theimmediate consequences operator T 3P .Proposition 81 Let Cli and Cl0i be clauses such that Cli ' Cl0i for any i 2 [0; n].If Cl 2 unfCl0(fCl1; : : : ; Clng) then there exists Cl0 2unfCl00(fCl01; : : : ; Cl0ng) suchthat Cl ' Cl0.26 Proof Let us assume Cl0 : p(~t0) c02p1(~t1); : : : ;pn(~tn) and Clj :pj(~lj) cj2~Ljfor j 2 [1; n]. We can also assume, without loss of generality, that the clause Clj isused to rewrite the atompj(~tj) in the unfolding unfCl0(fCl1; : : : ; Clng).By de nition 79, if Cl 2unfCl0(fCl1; : : : ; Clng) then the following constraintc0 n̂j=1(~ti =~li ^ ci)which we denote by c, is D-satis able. Moreover Cl is the clausep(~t0) c2~L1; : : : ; ~Ln:Let us assume Cl00 : p(~t00) c002p1(~t01); : : : ;pn(~t0n) and Cl0j :pj(~l0j)c0j2 ~L0j forj 2 [1; n], where all the clauses are renamed apart. Moreover let us denote by c0 theconstraintc00 n̂j=1(~t0j = ~l0j ^c0j):and by Cl0 the clausep(~t00) c02 ~L01; : : : ; ~L0nLet # be a solution of c. Clearly # is also a solution of ci for any i 2 [0; n]. SinceCl0 ' Cl00, there exists a solution 0 ofc00 such that ~ti# = ~t0i 0 holds for any i 2 [0; n].Moreover, since Clj ' Cl0j , there exists j solution ofc0j such that~lj# = ~l0j j and~Lj# = ~L0j j hold for any j 2 [1; n].Since the clauses Cl0i are renamed apart, the solutions i, for i 2 [0; n], can beextended to a unique solution ofVni=0 c0i such that ~t0 0 = ~t00 , ~l0j j = ~l0j and~L0j j = ~L0j hold for any j 2 [1; n]. This implies that is a solution of c0 suchthat ~t0# = ~t0i and ~Li# = ~L0j hold for any j 2 [1; n]. Therefore, by using also asimmetric argoment, we obtain Cl0 ' Cl which completes the proof.Proposition 82 T P is continuous on the complete lattice (D; ).Proof StandardSince T P is continuous, as usual T P " ! is its least xpoint on (D; ). We canthen de ne F (P ) as follows.De nition 83 (Compositional xpoint semantics) Let P be an -open pro-gram. The compositional xpoint semantics F (P ) of P is de ned as F (P ) =T P " !.7.2 Equivalence resultsThe equivalence between the operational and the xpoint semantics can be provedby introducing the intermediate notion of unfolding semantics U (P ) [35, 14] andfollowing the lines of the similar proof in [7]. U (P ) is obtained as the limit of the(top-down) unfolding process and is equivalent to the operational semantics O (P ).The proof of this equivalence is straightforward since O (P ) and U (P ) are based on27 the same inference rule. On the other side, the equivalence between U (P ) and thebottom-up semantics F (P ) can be based on the de nition T P (I) = unfP (I [ Id ).Let us rst formally de ne the unfolding semantics.De nition 84 Let P be a set of clauses. Then we de ne (P ) = fc 2 C j c 2 Pg:De nition 85 (Unfolding semantics) Let P be an -open program. Then wede ne the collection of programsP1 = PPn+1 = unfPn(P [ Id ):The unfolding semantics U (P ) of the program P is de ned asU (P ) = [nIn order to prove the equivalence we need two lemmata. The rst one states theassociativity of the unfolding operator.Lemma 86 Let P;Q;W be denotations. Then unfP (unfQ(W )) = unfunfP (Q)(W ).Proof By de nition 79, Cl 2 unfunfP (Q)(W ) i the following conditions hold1. 9 p(~t)c02p1(~t1); : : : ;pn(~tn) 2 P ,for i = 1; : : : ; n, 9pi(~ti) ci2qi;1(~ti;1); : : : ;qi;mi(~ti;mi) 2 Q,for j = 1; : : : ;mi, 9qi;j(~li;j) ci;j2 ~Bi;j 2W2. the constraint c0 ^Vni=1 ci[~ti =~liVmij=1 ci;j ^ (~ti;j =~li;j)], denotes by c, is D-satis able,3. Cl is the clause p(~t) c2 ~B1;1; : : : ; ~B1;m1 ; : : : ; ~Bn;1; : : : ; ~Bn;mn .Since these are exactly also the conditions for c 2 unfP (unfQ(W )) the thesis holds.Lemma 87 [7] Let P be an -open program, Pn be as in de nition 85 and letT P (I) = unfP (I [ Id ). Then for any n 1, T P " n = (Pn).Proof This lemma is proved in [7] for pure logic programs using only the associa-tivity of the unfolding rule, de nition 85 and the de nition T P (I) = unfP (I [ Id ).For the case of CLP we can repeat exactly the same proof using lemma 86.The following results state the equality of the unfolding, the operational and thexpoint semantics.Theorem 88 Let P be a program. Then F (P ) = U (P ).Proof By de nition, F (P ) = T P " !. Note that c 2 T P " ! i there exists n suchthat c 2 T P " n and c 2 U (P ) i there exists n such that c 2 (Pn). Then thethesis follows from lemma 87.28 In the following the length of a derivation D is the number of derivation steps inD.Theorem 89 Let P be an -open program. Then O (P ) = U (P ).Proof By de nitions 73 and 85, it su ces to prove that, for any h 1, if thereexists a derivation of length h true2p( ~X) P[Id; c2 ~Bthen there exists a clause cl 2 Pn such that cl ' p( ~X) c2 ~B and, conversely, ifcl is a clause in Pn whose head contains the predicate symbol p, then there exists aderivation as before such that cl ' p( ~X) c2 ~B.Note that, by de nition 79, given a clause cl : q(~t) c2A1; : : : ; An and a set ofclauses Q, we have q(~t) c; c02 ~A1; : : : ; ~An 2 unffclg(Q) i there exists a derivation(of length 2)true2q( ~X) fclg; c; ~X = ~t2A1; : : : ; An Q; c; ~X = ~t; c02 ~A1; : : : ; ~Anwhere ~X are new distinct variables. Therefore, by a straightforward inductive argu-ment, if there exists a derivation of length h 1true2p( ~X) P[Id; ~X = ~t; c2 ~Bthen the clause p(~t) c2 ~B is in Pn and clearly (p( ~X) ~X = ~t; c2B1; : : : ; Bn) '(p(~t) c2B1; : : : ; Bn). Analogously for the converse and therefore the thesis holds.Corollary 90 (Equivalence) Let P be an -open program. ThenF (P ) = O (P ).Proof Straightforward by theorems 88 and 89.Corollary 47 Let P be a program. Then O3(P ) = F3(P ).Proof Straightforward from proposition 74 and by corollary 90.8 Partial answers semanticsWe have introduced the semantics F in order to achieve [-compositionality. How-ever such a semantics allows us also to model several non-standard observables such aspartial answer constraints (partial answers for short) and call patterns. The interestin these observables arises from the context of program analysis and program opti-mization. Information on the partial results of computations can be used to detectwhich atoms in a goal are \independent" [25]. Independent atoms can be evaluatedin parallel, thus optimizing programs executions. In this section we will obtain fromsuitable abstractions of F a fully abstract semantic for partial answers and a correctsemantics for call patterns. In the case of pure logic programs, semantics for partialanswers were obtained in [16] and [23].A partial answer is the constraint computed by a derivation which is not yetterminated. We can make also a distinction between partial answers and correct29 partial answers, the latter requiring that the partial derivation be part of a successfulone. For example, the programs P1 = fr(X) X = a2qg and P2 = fq; r(X)X = a2qg have the same partial answers for the goal r(X), but not the same correctpartial answers. In the following de nitions, to simplify the notation, we use P; todenote also derivations of length 0. In such a case we assume that the resolvent is thegoal itself.De nition 91 Let P be a program and G be a goal with ~Y = V ar(G). The con-straint 9 ~Y c is a partial answer forG in P i there exists a derivationG P; c2 ~B. 9 ~Y cis a correct partial answer for G in P i there exists a derivation G P; c2 ~B P; c02.According to the procedural interpretation of (constraint) logic programs, an atompi(~ti) in a resolventc2p1(~t1); : : : ;pn(~tn) can be considered a \call" of the procedurepi( ~Xi) with parameters (implicitly) de ned by the constraint c ^ ~Xi = ~ti. We canthen de ne a (correct) \call pattern" as follows.De nition 92 Let P be a program and G be a goal. The pair hc; p(~t)i is a callpattern for the goal G in P i there exists a derivation G P; c2 ~B and p(~t) is anatom in ~B. hc; p(~t)i is a correct partial answer for G in P i there exists a derivationG P; c2 ~B P; c02 and p(~t) is an atom in ~B.The following is the formal de nition of the equivalences induced by these observ-ables.De nition 93 Let P1; P2 be programs, G be a goal and let ~Y = V ar(G). Then wede neP1 p P2 (P1 c P2) i , for any G and for any i; j 2 [1; 2], if G has a partialanswer (correct partial answer) ci in Pi then G has a partial answer (correctpartial answer) cj in Pj such that D j= 9 ~Y ci $ 9 ~Y cj .P1 pt P2 (P1 cpt P2) i , for any G and for any i; j 2 [1; 2], if G has a callpattern (correct call pattern) hci; p(~ti)i in Pi then G has a call pattern (correctcall pattern) hcj ; p(~tj)i and p(~ti) ci ' p(~tj) cj .Since B is the set of all the predicates symbols which are not used as constraints,F B (P ) can be considered as a kind of collecting semantics which gives the maximumamount of information on computations in the program P . Therefore we can extractfrom the clauses in F B (P ) all the information needed to model partial answersand call patterns. For example, since each clause p( ~X)c2p1(~t1); : : : ;pn(~tn) inF B (P ) corresponds to a derivation p( ~X) P;c2p1(~t1); : : : ;pn(~tn), if there exists aclause p( ~X)c2p1(~t1); : : : ;pn(~tn) 2 F B (P ) such that d : (~l = ~X; c) is D-solvable,then there exists a partial answer 9 ~Y cp for the goal true2p(~l) in P such that D j=9 ~Y cp $ 9 ~Y d (and vice versa). Moreover, if there exist n unit clausespi(~li) ci 2F B (P ) such that (cp; c1; ~t1 =~l1; : : : ; cn; ~tn =~ln) is D-solvable, then 9 ~Y cp is also acorrect partial answer. Note that, in the case of partial answers, we only need theinformation in the heads and in the constraints of the clauses in F B (P ), while thisis not the case for correct partial answers. Therefore the following.30 De nition 94 (Partial answers semantics) Let P be a program. The partialanswer semantics P(P ) and the correct partial answer semantics Pc(P ) of P arede ned as followsP(P ) = fH c 2 C j there exists H c2B1; : : : ; Bn 2 F B (P )gPc(P ) = fHc2p1(~t1); : : : ;pn(~tn) 2 F B (P ) jfor i = 1; : : : ; n; there existspi(~li) ci 2 F B (P );renamed apart such thatcVni=1(ci ^ ~ti =~li) is D-solvableg:The following lemma, whose proof is in the appendix, shows how we can obtain apartial answer for a goal G by \evaluating" G in the semantics. Theorems 96 and 97give the correctness and full abstraction results.Lemma 95 Let P be a program, G :c02p1(~t1); : : : ;pn(~tn) be a goal and let ~Y =V ar(G).1. There exists a partial answer cp for G in P with D j= 9 ~Y cp $ 9 ~Y d i forany i 2 [1; n] there existspi(~li) ci2: 2 P(P ) renamed apart, such thatc0p :(c0Vni=1(ci ^ ~ti =~li)) is D-solvable and D j= 9 ~Y c0p $ 9 ~Y d.2. There exists a correct partial answer cp for G in P with D j= 9 ~Y cp $ 9 ~Y di for any i 2 [1; n] there existpi(~li)c0i2qi;1(~ti;1); : : : ;qi;mi(~ti;mi) 2 Pc(P )and for j = 1; : : : ;mi there existqi;j(~li;j)c0i;j2 2 Pc(P ) all renamed apart,such that[c0Vni=1(ci ^ ~ti =~liVmij=1 ci;j ^ (~ti;j =~li;j))] is D-solvable and D j=9 ~Y c0p $ 9 ~Y d wherec0p is the constraint[c0Vni=1 ci ^ (~ti =~li)].Theorem 96 (Correctness of Pc) Let P1; P2 be programs. Then the followingstatements hold1. Pc(P1) c P12. if Pc(P1) = Pc(P2) then P1 c P2.Proof Straightforward by lemma 95 and by de nition 93.Theorem 97 (Full abstraction of P) Let P1; P2 be programs. Then the follow-ing statements hold1. P(P1) p P12. P(P1) = P(P2) i P1 p P2.Proof The proofs of 1 and of the only if part of 2 are straightforward by lemma95 and by de nition 93. The proof of the if part of 2 is by contradiction. Let usassume P1 p P2 and, without of loss of generality, that p( ~X) c 2 P(P1) n P(P2).Note that, by de nitions 73 and 94, for any P , p( ~X) true 2 P(P ). Thereforep( ~X) c 6' p( ~X) true (i.e. D 6j= 9 ~Xc $ true). By lemma 95 the goal c2p( ~X)has a partial answer c1 in P1 such that D j= 9 ~Xc$ 9 ~Xc1. Moreover, for any partialanswer c2 of c2p( ~X) in P2, D 6j= 9 ~Xc $ 9 ~Xc2. This contradicts the assumptionP1 p P2 and completes the proof.31 The information needed to model call patterns can be obtained from the F Bsemantics as well. For example, if p(~t) c2B1; : : : ; Bn 2 F B (P ), then hc0; Bii is acall pattern for the goal p(~l) i c0 : (c^~l = ~t) is D-solvable for any i, 1 i n. Notethat we only need the information on the relation between the head, the constraintand the various atoms in the body. In other words, the clause H c2B1; : : : ; Bnis equivalent to the set of clauses fH c2B1; : : : ; H c2Bng. In order to modelcorrect call patterns instead we need to keep all the information on the clause bodies.We give below only the de nitions of the semantics and the correctness result. Theproofs are similar to the previous ones.De nition 98 Let P be a program. The call patterns semantics Ppt(P ) and thecorrect call pattern semantics Pcpt(P ) are de ned as followsPpt(P ) = fH c 2 C j 9H c 2 F B (P )g[ fH c2B 2 C j 9H c2B1; : : : ; Bn 2 F B (P ); B = Bi; 1 i ngPcpt(P ) = Pc(P ):Theorem 99 Let P1; P2 be programs. Then the following statements hold1: Ppt(P1) pt P1;2: If Ppt(P1) = Ppt(P2) then P1 pt P23: Pcpt(P1) cpt P1;4: If Pcpt(P1) = Pcpt(P2) then P1 cpt P2:9 ConclusionsIn this paper we have formalized a framework for de ning several semantics for CLPprograms. In particular, we have de ned an operational semantics O3 and an equiv-alent xpoint semantics F3 which models answer constraints in a fully abstract way.This is not the case for the semantics F1 and O2 previously de ned for CLP [29], sincethey were correct only wrt a notion of observable di erent from answer constraints.We have given a notion of -model based on the standard notion of truth which allowsus to show that all our (non compositional semantics) are -models. Finally we havede ned a semantics F , which models answer constraints and is compositional wrtthe union of programs. Suitable abstractions of F allow to obtain a fully abstractsemantics P for partial answers and a correct semantics Ppt for call patterns. Thefollowing points summarize the properties of our constructions.We have equivalent operational and xpoint formalizations of all the semantics.The non compositional semantics de ne di erent -models which capture dif-ferent operational properties. However they characterize exactly the same setsof true formulas.Each D-model has a corresponding -model which gives the same information.There exists the least -model (according to a suitable order) which is the sameas the standard least D-model and is equivalent to the ground success set F1.The answer constraint semantics F3 is a non-minimal -model. In general,minimal models are adequate from a logical point of view, but some richermodels are needed to model observable behaviors.32 The compositional semantics F is obtained by a natural extension of F1 byusing a semantic domain based on clauses. F is a kind of \collecting" se-mantics from which one can obtain, by suitable abstractions, information onnon-standard observables (such as partial answers and call patterns.We have shown the algebraic formulation of the semantics. Equivalent logicalde nitions can be obtained by using the notion of corresponding theory. Inparticular, logical versions of the operational semantics O2 and of the xpointsemantics F3 were de ned in [29] by using a theory T corresponding to D anda \hybrid" approach: at each step of the evaluation a part of the constraint canbe solved by applying a (most general) T -satis er. We refer to [19] for the proofof the equivalence between the algebraic and the logical (\hybrid") versions ofall the previously considered semantics.All our results, apart from proposition 33 and theorems 43,58, can be extendedto the constraint language de ned in [27], where the solution compactness prop-erty is not required.Our framework for the semantics of constraint logic program can be used for someapplications that we brie y discuss below.Program analysis.The answer constraint semantics F3 can be used to develop semantics basedtools for the analysis of CLP programs. Abstract interpretation of CLP pro-grams has been considered in a denotational semantics framework in [38], whileby using suitable abstract versions of the immediate consequence operators T 3Pwe can generalize the bottom-up approach in [3]. The compositional semanticsin [7] has been used in [10] to develop a modular analysis for pure logic pro-grams. Analogously, our F semantics and its operator T P can be taken asthe basis to de ne a framework for the compositional abstract interpretation ofCLP programs, thus providing the same bene ts discussed in [10] in terms ofcomplexity and reusability of the analysis.It is worth noting that in many applications based on abstract interpretationthe set of (possibly abstract) values for variables is nite. In such a case, bya slight modi cation of the de nition of F (analogous to that one in [20] forpure logic programs), we can obtain a semantics which is compositional (wrt [)and nite, thus satisfying the termination properties required for the analysis.(Abstractions of) the partial answer semantics P can be used to analyze pro-grams in order to optimize programs executions. For example, partial answerscan be used to detect \independence" of CLP goals ([25]), thus providing theconditions for optimizations based on AND-parallelism and intelligent back-tracking.Using our constructions, abstract interpretation can be reduced to a purelyalgebraic operation on the particular structure D on which the computationis performed. In order to perform the abstraction process, we need a suit-able notion of D-abstract solution (instead of D-solution), while the derivationmechanism remains the same of the concrete one. Depending on the kind ofconstraints we are considering and on the kind of analysis to be performed, the33 notion of D-abstract solution has to satisfy the usual properties of correctness.The complete separation between the derivation mechanism and the (abstract)D-solution computation makes the formalism more elegant and make easier toverify the algebraic properties which guarantee the correctness.Transformations.The answer constraint semantics and its compositional version can be taken asthe reference semantics to be preserved by transformation systems. A Fold/Unfoldtransformation for CLP, based on the system de ned by Tamaki and Sato forpure logic programs ([40]), has been de ned in [13] and has been proved cor-rect wrt F (and hence wrt F3). Since the system preserves the compositionalsemantics, it can be used for the modular transformation of programs.Update speci cations.In the context of languages for deductive databases, updates are importantprogramming facilities (similar to assert and retract of PROLOG). [4] de nes aconstraint logic language ECD with elementary updates to model the dynamicbehavior of database systems. The semantics of ECD is obtained by using anextension of our constructions. Since updates in ECD are expressed by meansof constraints, such a semantics provides a declarative characterization of thesemechanisms which usually have an operational description only.Equational languages.Functional (i.e. equational) languages and logic programming can be integratedwithin the CLP paradigm. [1] proposes a language CLP(H=E) which is spe-cialized in solving equations with respect to a Horn equational theory E . Theoperational semantics of CLP(H=E) is de ned by an (incremental) constraintsolver based on conditional narrowing. The declarative semantics of CLP(H=E)is obtained by using our answer constraint semantics [2].AcknowledgmentsWe thank Maria Chiara Meo and the anonymous referees of the paper for their usefulcomments.References[1] M. Alpuente and M. Falaschi. Narrowing as an Incremental Constraint Satisfac-tion Algorithm. In J. Maluszynski and M. Wirsing, editors, Proc. of PLILP'91,volume 528 of Lecture Notes in Computer Science, pages 111{122. Springer-Verlag, Berlin, 1991.[2] M. Alpuente, M. Falaschi, M. Gabbrielli, and G. Levi. The semantics of equa-tional logic programming as an instance of CLP. In K. R. Apt, J. W. de Bakker,and J. J. M. M. Rutten, editors, Logic Programming Languages: Constraints,Functions and Objects, pages 49{81. The MIT Press, Cambridge, Mass., 1993.34 [3] R. Barbuti, R. Giacobazzi, and G. Levi. A General Framework for Semantics-based Bottom-up Abstract Interpretation of Logic Programs. ACM Transactionson Programming Languages and Systems, 15(1):133{181, 1993.[4] E. Bertino, M. Martelli, and D. Montesi. Modeling Database Updates withConstraint Logic Programming. In Proc. Fourth Int'l Work. on Foundations ofModels and Languages for Data and Objects, 1992.[5] A. Bossi, M. Bugliesi, M. Gabbrielli, G. Levi, and M. C. Meo. Di erentiallogic programming. In Proc. Twentieth Annual ACM Symp. on Principles ofProgramming Languages, pages 359{370. ACM Press, 1993.[6] A. Bossi, M. Gabbrielli, G. Levi, and M. Martelli. The s-semantics approach:Theory and applications. Technical Report TR 9/93, Dipartimento di Informat-ica, Universita di Pisa, 1993. To appear in the Journal of Logic Programming.[7] A. Bossi, M. Gabbrielli, G. Levi, and M. C. Meo. A Compositional Semanticsfor Logic Programs. Theoretical Computer Science, 122(1-2):3{47, 1994.[8] A. Bossi and M. Menegus. Una Semantica Composizionale per Programmi LogiciAperti. In P. Asirelli, editor, Proc. Sixth Italian Conference on Logic Program-ming, pages 95{109, 1991.[9] K. L. Clark. Negation as Failure. In H. Gallaire and J. Minker, editors, Logicand Data Bases, pages 293{322. Plenum Press, New York, 1978.[10] M. Codish, S. K. Debray, and R. Giacobazzi. Compositional Analysis of Mod-ular Logic Programs. In Proc. Twentieth Annual ACM Symp. on Principles ofProgramming Languages, pages 451{464. ACM Press, 1993.[11] A. Colmerauer. Prolog and In nite Trees. In K. L. Clark and S. A. Tarnlund,editors, Logic Programming, pages 231{251. Academic Press, New York, 1982.[12] H. Comon and P. Lescanne. Equational Problems and Disuni cation. Journal ofSymbolic Computation, 7:371{425, 1989.[13] S. Etalle and M. Gabbrielli. Modular Transformations for Constraint Logic Pro-grams. Submitted for publication.[14] F. Denis and J.-P. Delahaye. Unfolding, Procedural and Fixpoint Semantics ofLogic Programs. In C. Cho rut and M. Jantzen, editors, STACS 91, volume 480of Lecture Notes in Computer Science, pages 511{522. Springer-Verlag, Berlin,1991.[15] N. Heintze et al. The CLP Programmer's Manual. Dept. of Computer Science,Monash University, Australia, 1986.[16] M. Falaschi and G. Levi. Finite failures and partial computations in concurrentlogic languages. Theoretical Computer Science, 75:45{66, 1990.[17] M. Falaschi, G. Levi, M. Martelli, and C. Palamidessi. Declarative Modeling ofthe Operational Behavior of Logic Languages. Theoretical Computer Science,69(3):289{318, 1989.35 [18] M. Falaschi, G. Levi, M. Martelli, and C. Palamidessi. A Model-Theoretic Re-construction of the Operational Semantics of Logic Programs. Information andComputation, 102(1):86{113, 1993.[19] M. Gabbrielli. The Semantics of Logic Programming as a Programming Lan-guage. PhD thesis, Dipartimento di Informatica, Universita di Pisa, 1993.[20] M. Gabbrielli, R. Giacobazzi, and D. Montesi. Modular logic programs over nitedomains. In D. Sacca, editor, Proc. Eight Italian Conference on Logic Program-ming, pages 663{678, 1993. Extended version as Technical Report Laboratoired'Informatique, Ecole Politechnique, LIX/RR/94/04, 1994.[21] M. Gabbrielli and G. Levi. Modeling Answer Constraints in Constraint LogicPrograms. In K. Furukawa, editor, Proc. Eighth Int'l Conf. on Logic Program-ming, pages 238{ 252. The MIT Press, Cambridge, Mass., 1991.[22] M. Gabbrielli and G. Levi. On the Semantics of Logic Programs. In J. LeachAlbert, B. Monien, and M. Rodriguez-Artalejo, editors, Automata, Languagesand Programming, 18th International Colloquium, volume 510 of Lecture Notesin Computer Science, pages 1{19. Springer-Verlag, Berlin, 1991.[23] M. Gabbrielli and M. C. Meo. Fixpoint Semantics for Partial Computed AnswerSubstitutions and Call Patterns. In H. Kirchner and G. Levi, editors, Algebraicand Logic Programming, Proceedings of the Third International Conference, vol-ume 632 of Lecture Notes in Computer Science, pages 84{99. Springer-Verlag,Berlin, 1992.[24] H. Gaifman and E. Shapiro. Fully abstract compositional semantics for logicprograms. In Proc. Sixteenth Annual ACM Symp. on Principles of ProgrammingLanguages, pages 134{142. ACM, 1989.[25] M.J. Garcia de la Banda, M. Hermenegildo, and K. Marriott. Independence inConstraint Logic Programs. In Proceedings of the International Logic Program-ming Symposium, pages 130{146, MIT Press, Cambridge, MA 1993.[26] R. Giacobazzi, S. K. Debray, and G. Levi. A Generalized Semantics for Con-straint Logic Programs. In Proceedings of the International Conference on FifthGeneration Computer Systems 1992, pages 581{591, 1992.[27] M. Hohfeld and G. Smolka. De nite relations over constraint languages. LILOGreport 53, IBM Deutschland GmbH, Stuttgart, 1988.[28] J. Ja ar and J.-L. Lassez. Constraint Logic Programming. In Proc. FourteenthAnnual ACM Symp. on Principles of Programming Languages, pages 111{119.ACM, 1987.[29] J. Ja ar and J.-L. Lassez. Constraint Logic Programming. Technical report,Department of Computer Science, Monash University, June 1986.[30] J. Ja ar and M. Maher. Constraint Logic Programming: a Survey. Technicalreport, 1994. To appear in the Journal of Logic Programming.36 [31] J. Ja ar, S. Michaylov, P. Stuckey, and R.H.C Yap. An Abstract Machine forCLP(R). In ACM Programming Language Design and Implementation, vol-ume 27 of SIGPLAN Notices, pages 128{139. ACM Press, 1992.[32] C. Kirchner and P. Lescanne. Solving Disequations. In Proc. Second IEEE Symp.on Logic In Computer Science, pages 347{352. IEEE Computer Society Press,1987.[33] J.-L. Lassez, M. J. Maher, and K. Marriott. Uni cation Revisited. In J. Minker,editor, Foundations of Deductive Databases and Logic Programming, pages 587{625. Morgan Kaufmann, Los Altos, Ca., 1988.[34] J.-L. Lassez and K. McAloon. Applications of a canonical form for generalizedlinear constraints. In Proc. Int'l Conf. on Fifth Generation Computer Systems,pages 703{710, Tokyo, 1988. Institute for New Generation Computer Technology,Tokyo.[35] G. Levi and P. Mancarella. The Unfolding Semantics of Logic Programs. Tech-nical Report TR-13/88, Dipartimento di Informatica, Universita di Pisa, 1988.[36] M. Maher. A CLP View of Logic Programming. In H. Kirchner and G. Levi, ed-itors, Proceedings of Third International Conference on Algebraic and Logic Pro-gramming, Lecture Notes in Computer Science, pages 364{383. Springer-Verlag,Berlin, 1992.[37] M. J. Maher. A Logic Programming view of CLP. In D. S. Warren, editor,Proc. Tenth Int'l Conf. on Logic Programming, pages 737{753. The MIT Press,Cambridge, Mass., 1993.[38] K. Marriott and H. S ndergaard. Analysis of Constraint Logic Programs. InS. K. Debray and M. Hermenegildo, editors, Proc. North American Conf. onLogic Programming, pages 531{547. The MIT Press, Cambridge, Mass., 1990.[39] V. A. Saraswat, M. Rinard, and P. Panangaden. Semantic Foundation of Con-current Constraint Programming. In Proc. Eighteenth Annual ACM Symp. onPrinciples of Programming Languages, pages 333{353. ACM, 1991.[40] H. Tamaki and T. Sato. Unfold/Fold Transformations of Logic Programs. InStenAke Tarnlund, editor, Proc. Second Int'l Conf. on Logic Programming,pages 127{139, 1984.37 A Appendix: proofsIn this appendix we rst prove one basic (strong) lifting lemma for CLP (lemma 102):the resultants (i.e. the answer constraints together with a resolvent) for a goal G canbe obtained from the resultants of the \non-constrained" versions of the atoms in G,and vice versa. Such a lemma was used the prove the correctness and full abstractionof the F3(P ) semantics (lemma 27 and corollary 29). Using lemma 102 we will thenprove the compositionality of the F (P ) semantics (theorem 75) and lemma 95, whichwas used to show the correctness and full abstraction of the partial answer semantics.We rst need two simple results.Lemma 100 Let q( ~Y ) ci2 ~Ai ' q( ~Y ) di2 ~Bi for i = 1; : : : ; n and let V ar(ci; ~Ai)\V ar(cj ; ~Aj) ~Y , V ar(di; ~Bi) \ V ar(dj ; ~Bj) ~Y for i 6= j. Thenq( ~Y ) c1; : : : ; cn2 ~A1; : : : ; ~An ' q( ~Y ) d1; : : : ; dn2 ~B1; : : : ; ~Bn:Proof Let # be a solution of c1^: : :^cn. Then, for 1 i n, # is a solution of ci andsince by hypothesis q( ~Y ) ci2 ~Ai ' q( ~Y ) di2 ~Bi, there exists i solution of di suchthat ~Y # = ~Y i and ~Ai# = ~Bi i. Since by hypothesis V ar(di; ~Bi) \ V ar(dj ; ~Bj) ~Yfor de ned by(y) =i(y)if y 2 V ar(di; ~Bi) n ~Y1(y) = 2(y) = : : : = n(y) if y 2 ~Y;we have that is a solution of d1^ : : :^dn, ~Y # = ~Y and, for i = 1; : : : ; n, ~Ai# = ~Bi .Since the converse holds by symmetry, this completes the proof.The following lemma shows that we can obtain from a derivation D an equivalentderivation D0 by adding some derivation steps where some atoms are rewritten byusing clauses in Id . We assume that atoms are superscripted by an index whichdenotes their level in the derivation (0 for the goal, 1 for the rst resolvent etc.).Lemma 101 Let P be a program, G0 be a goal and be a set of predicate symbols.Assume that ~Y = V ar(G0) and P = P [ Id . If there exists a derivation D : G0 P;c2 ~Bn with Pred( ~Bn), then there exists a derivation D0 : G0 P; c02 ~B0m suchthat(i) p( ~Y ) c2 ~Bn ' p( ~Y ) c02 ~B0m and(ii) D0 is any modi cation of the derivationD which satis es the following conditions:1. if Pred(Bi) 2 and the atom Bi in (the i-th resolvent of) D is eithernot rewritten (if i = n) or it is rewritten by using the clause cl, then inD0 the atom Bi is either rewritten by cl or it is rewritten by a clauseH c2H 2 Id and Hj+1 is marked by the pair (cl; i) in the resolventobtained;2. if the atom Bj in D0 is marked by (cl; i), then either Bj is rewritten (in D0)by a clause H c2H 2 Id and Hj+1 is marked by (cl; i) in the resolventobtained, or Bj is rewritten by cl = H c2A1; : : : ; An and the resolventobtained contains the atoms Ai+11 ; : : : ; Ai+1n which are not marked;38 3. ~B0m contains no marked atoms.Proof Let us consider a resolvent G :c02p1(~t1) : : : ;pn(~tn) and assume that thereexists a derivation stepG P;c2q1(~t1); : : : ;qn(~tn);performed by using the clausespi(~li) ci2qi(~si) 2 P , i = 1; : : : ; n, wherec = (c0 n̂i=1 ~ti =~li ^ ci)(we consider clauses with only one atom in the body to simplify the notation. Theextension to the general case is obvious). Let us now assume that, according to thede nition of D0, some atoms in G, say the rst m, are rst rewritten by clauses inId and then by the clauses in P , and conversely for the other n m atoms. Let~X1; : : : ; ~Xn be tuples of distinct new variables. Clearly if c is D-solvable then alsoc0 = [c0 m̂i=1(~ti = ~Xi ^ ~Xi =~li ^ ci) n̂j=m+1(~tj =~lj ^ cj ^ ~sj = ~Xj)]is D solvable. Moreover each solution of c0 is a solution of c, and each solution ofc can be extended to a solution # of c0 such that for y 2 V ar(c), y# = y and fori = m+ 1; : : : ; n, ~Xi = ~si . Therefore, we have also a derivationG Id [P; c12p1( ~X1) : : : ; pm( ~Xm); qm+1(~sm+1); : : : ; qn(~sn) Id [P;c02q1(~s1) : : : ; qm(~sm); qm+1( ~Xm+1); : : : ; qn( ~Xn)where c0 is de ned as before andc1 = [c0 m̂i=1(~ti = ~Xi ^ ci) n̂j=m+1(~tj =~lj ^ cj)]:Because of the above properties of c0, for ~Y = V ar(G) we havep( ~Y )c2q1(~t1); : : : ;qn(~tn)'p( ~Y )c02q1(~s1) : : : ; qm(~sm); qm+1( ~Xm+1); : : : ; qn( ~Xn):Therefore the thesis holds by a straightforward inductive argument.Lemma 102 Let P be a program, G : c02p1( ~t1); : : : ; pn( ~tn) be a goal, be a set ofpredicate symbols and let P = P [ Id . If there exists a derivationG P; ca2 ~A1; : : : ; ~Ansuch that Pred( ~A1; : : : ; ~An)then the following hold(i) for any i 2 [1; n] there exists a derivation true2pi( ~Xi) P; ci2 ~Bi which share novariables with G and with each other, such that Pred( ~Bi) ,39 (ii) cb =(c0Vni=1 ci ^ ~Xi = ~ti) is D-solvable,(iii) q( ~Y ) ca2 ~A1; : : : ; ~An ' q( ~Y ) cb2 ~B1; : : : ; ~Bn for ~Y = V ar(G).Conversely, if (i) and (ii) hold, then there exists a derivation G P; ca2 ~A1; : : : ; ~Ansuch that (iii) holds.Proof In the following we denote by i a generic index in [1; n].())Assume, without loss of generality, that ~Ai is the (possibly empty) multiset of atomsderived frompi(~ti) in the derivation c02p1( ~t1); : : : ; pn( ~tn) (P ); ca2 ~A1; : : : ; ~An and letus denote by D such a derivation. Letpi(~li) be the head of the ( rst) clause used torewritepi(~ti). By de nition of derivation step for any i there exists a derivationc02pi(~ti) P; ~ti = ~li; c0; ci2 ~Aiandca = (c0 n̂i=1 ~ti = ~li ^ ci):(1)Note that if the variables ~X do not appear in ~t; ~l; c, by de nition of D-solution,any D-solution of ~t = ~l^ c can be extended to a D-solution of ~t = ~X ^ ~X = ~l^ c, andany D-solution of ~t = ~X ^ ~X = ~l ^ c is also an D-solution of ~t = ~l ^ c. Therefore, for~Yi = V ar(ti; li; ci; c0; ~Ai) ,q( ~Yi) ~ti =~li; ci; c02 ~Ai ' q( ~Yi) ~ti = ~Xi; ~Xi =~li; ci; c02 ~Ai:(2)Moreover, if c ^ c0 is D-solvable obviously also c is solvable. Therefore, since ~Xiare new distinct variables, by considering suitably renamed version of clauses, thereexist the derivationstrue2pi( ~Xi) P; ~Xi =~li; ci2 ~BiSince the only variables common to the di erent derivations are contained inSni=1 ~Yiand ~YSni=1 ~Yi the thesis follows by (1), (2) and lemma 100.(()Assume that for any i 2 [1; n] there exist the following n derivations of length hi (i.e.containing hi derivation steps)true2pi( ~Xi) P; ~Xi =~li; ci2 ~Bisuch thatcb = (c0 n̂i=1 ~Xi = ~li ^ ~Xi = ~ti ^ ci)(3)is D-solvable (as before,pi(~li) is the head of the rst clause used for any derivation).By the same argument of the ) case, there exist n derivations of length hic02pi(~ti) P; ~ti = c0; ~li; ci2 ~Bi40 such thatc0a = (c0 n̂i=1 ~ti =~li ^ ci)is D-solvable and, for ~Y = V ar(G),q( ~Y )c0a2 ~B1; : : : ; ~Bn ' q( ~Y ) cb2 ~B1; : : : ; ~Bn:(4)Now let us consider k = maxfhi j i = 1; : : : ; ng. By de nition of P , we have alson derivations of length k c02pi(~ti) P; c0; ~ti =~li; ci;cvi2 ~Aiwhere, for hi < k,cvi contains bindings for the terms in ~Bi with the new (renamedapart) variables used for the clauses in Id . By lemma 101, for ~Wi=V ar(c0; ~ti; ~li;c0i)q( ~Wi) ~ti =~li; ci;cvi2 ~Ai ' q( ~Wi) ~ti =~li; ci2 ~Bi(5)Since the only variables shared among the di erent derivations are contained inSni=1Wi and ~YSni=1Wi by (4) and by lemma 100 follows thatq( ~Y ) ca2 ~A1; : : : ; ~An ' q( ~Y ) cb2 ~B1; : : : ; ~Bn(6)whereca = (c0 n̂i=1 ~ti = ~li ^ ci ^cvi )is D solvable. By using the same clauses used in the n derivations (of equal length),since ca is D solvable, we have also a derivation G P; ca2 ~A1; : : : ; ~An and this togetherwith (6) completes the proof.sWe prove now the compositionality of the semantics O .Theorem 103 (Theorem 75) Let P1 be an 1-open program, P2 be an 2-openprogram and let P1 [ P2 be de ned. ThenO (O 1(P1) [ O 2(P2)) = O (P1 [ P2):Proof First note that, by de nition 73, Pred(O (P )) Pred(P ). Therefore, byde nition 68, if P1[ P2 is de ned then also O 1(P1)[ O 2(P2) is de ned. Moreoverrecall that if P1 [ P2 is de ned, then P1 [ P2 is the -open program P1 [ P2. Letus de ne W1 = P1 [ P2 [ Id and W2 = O 1(P1) [ O 2(P2) [ Id . By de nition 73it is then su cient to show that if there exists a derivationtrue2p( ~X) W1; c2B1; : : : ; Bnsuch that Pred(B1; : : : ; Bn; )then there exists a derivationtrue2p( ~X) W2; c02B01; : : : ; B0n41 with p( ~X) c2B1; : : : ; Bn ' p( ~X) c02B01; : : : ; B0n and vice versa.Let us prove the two implications separately.())Assume that there exists a derivationtrue2p( ~X) W1; c2B1; : : : ; Bnwhich we denote by D, such that Pred(B1; : : : ; Bn). Let us denote by ; amodi cation of the usual derivation rule which satis es the following condition.(i) For any resolvent R =q1(~l1); : : : ;qm(~lm) in a ; derivation, if there exists j 2[1;m] such that qj 62 , then, for any i 2 [1;m] such that qi 2 ,qi(~li) isrewritten by using a clause in Id .Since Pred(B1; : : : ; Bn) , by lemma 101 there exists a derivation D0true2p( ~X) W1; c02B01; : : : ; B0nsuch that p( ~X) c2B1; : : : ; Bn ' p( ~X) c02B01; : : : ; B0n and Pred(B01; : : : ; B0n). Obviously, any ; derivation is also a ; derivation. Then we can restrict toconsider ; derivations only. Let us then suppose that there exists a derivation D0of length m 1co2p1(~t1); : : : ;pm(~tm) W1; c2 ~B1; : : : ; ~Bmsuch that Pred( ~B; : : : ; ~Bm)and where, without loss of generality, we denote by~Bi the atoms derived frompi(~ti). Observe that, by de nition of [ , all the predicatesymbols shared by P1 and P2 are contained in . Let ca2 ~A1; : : : ; ~Am be the rstresolvent in the derivation D0 such that Pred( ~A1; : : : ; ~Am) . As a consequence, ifa \non-open" atom q(~l) (i.e. such that q 62 ) is rewritten by a a clause c 2 P1 in thederivationco2p1(~t1); : : : ;pm(~tm) W1; ca2 ~A1; : : : ; ~Amthen all the atoms derived from q(~l) are rewritten by clauses in P1 [ Id . Symmetri-cally for P2. By de nition of ; and by lemma 102 we then have m derivationstrue2pi( ~Xi) Ph[Id; ci2 ~A0isuch that 1 h 2,c0a =(c0Vni=1 ci ^ ~Xi = ~ti) is D-solvable and for~Y = Var(c02p1(~t1); : : : ;pm(~tm))r( ~Y ) ca2 ~A1; : : : ; ~Am ' r( ~Y )c0a2 ~A01; : : : ; ~A0m:(1)By de nition of O (P ) this implies that there exist m clauses pi( ~Xi) ci2 ~A0i 2W2 such that (in one derivation step)c02p1(~t1); : : : ;pm(~tm) W2;c0a2 ~A01; : : : ; ~A0m:Therefore the thesis holds by (1), by de nition of ca2 ~A1; : : : ; ~Am and by a straight-forward inductive argument.42 (()Assume that there exists a derivation stepc02p1(~t1); : : : ;pn(~tn) W2; c2 ~B1; : : : ; ~Bn:which uses the n clauses pi( ~Xi) ci2 ~Bi in W2 and wherec = (c0 n̂i=1 ~Xi = ~ti ^ ci)By de nition of W2 and by de nition 73 there exist n derivationstrue2p( ~X) W1; ci2 ~Bi:Since c is satis able, by lemma 102 there exists the derivationc02p1(~t1); : : : ;pn(~tn) W1; c02 ~B01; : : : ; ~B0nand, for ~Y = Var(c02p1(~t1); : : : ;pm(~tm)),q( ~Y ) c2 ~B1; : : : ; ~Bn ' q( ~Y ) c02 ~B01; : : : ; ~B0n:Therefore the thesis holds by a straightforward inductive argument.Finally we prove the lemma needed for the correctness and full abstraction of thepartial answer semantics.Lemma 95 Let P be a program, G :c02p1(~t1); : : : ;pn(~tn) be a goal and let~Y = V ar(G).1. There exists a partial answer cp for G in P with D j= 9 ~Y cp $ 9 ~Y d i forany i 2 [1; n] there existspi(~li) ci2: 2 P(P ) renamed apart, such thatc0p :(c0Vni=1(ci ^ ~ti =~li)) is D-solvable and D j= 9 ~Y c0p $ 9 ~Y d.2. There exists a correct partial answer cp for G in P with D j= 9 ~Y cp $ 9 ~Y di for any i 2 [1; n] there existpi(~li)c0i2qi;1(~ti;1); : : : ;qi;mi(~ti;mi) 2 Pc(P )and for j = 1; : : : ;mi there existqi;j(~li;j)c0i;j2 2 Pc(P ) all renamed apart,such that[c0Vni=1(ci ^ ~ti =~liVmij=1 ci;j ^ (~ti;j =~li;j))] is D-solvable and D j=9 ~Y c0p $ 9 ~Y d wherec0p is the constraint[c0Vni=1 ci ^ (~ti =~li)].Proof By lemma 101, P and P = P [ Id B have the same partial answers (upto ' equivalence). Therefore in the following we will assume that P contains Id B .Let us assume ~Y = V ar(G) where G =c02p1(~t1); : : : ;pn(~tn). By lemma 102, if thereexists a derivationG P; c2 ~B1; : : : ; ~Bnthen there exist n derivations true2pi( ~Xi) P; ci2 ~Ai43 such that, for c0 =(c0Vni=1 ci ^ ~Xi = ~ti),q( ~Y ) c2 ~B1; : : : ; ~Bn ' q( ~Y ) c02 ~A1; : : : ; ~An(1)holds. By de nitions 73 and 94 we havepi( ~Xi) P; ci2 ~Ai i pi( ~Xi) ci2 ~Ai 2 F B (P ) i pi( ~Xi) ci2 2 P(P ):Therefore de nition 91 and (1) imply that the ()) implication of the rst part holds.The proof of the other implication is analogous.For the second part, observe that proposition 74 and theorem 28 imply that a goalG0 = c02q1;1(~s1;1); : : : ;qn;mn(~sn;mn)has a successful derivation in P i , for i = 1; : : : ; n and j = 1; : : : ;mi, there existqi;j(~li;j)c0i;j2 2 F B (P ) such that[c0Vni=1(ci ^ ~ti =~liVmij=1 ci;j ^ ~ti;j =~li;j)] isD-solvable. The remaining of the proof is analogous to the one of the rst part of thelemma.44

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Phase Semantics and Veriication of Concurrent Constraint Programs Frann Cois Fages Paul Ruet

The class CC of concurrent constraint programming languages and its non-monotonic extension LCC based on linear constraint systems can be given a logical semantics in Girard's intuitionistic linear logic for a variety of observables. In this paper we settle basic completeness results and we show how the phase semantics of linear logic can be used to provide simple and very concise \semantical" ...

متن کامل

Phase Semantics and Veri cation of Concurrent Constraint

The class CC of concurrent constraint programming languages and its non-monotonic extension LCC based on linear constraint systems can be given a logical semantics in Girard's intuitionistic linear logic for a variety of observables. In this paper we settle basic completeness results and we show how the phase semantics of linear logic can be used to provide simple and very concise \semantical" ...

متن کامل

Modeling Answer Constraints in Constraint Logic Programs

The constraint logic programming paradigm CLP(X) (CLP for short) has been proposed by Jaaar and Lassez in order to integrate a generic computational mechanism based on constraints with the logic programming framework. This paradigm retains the semantic properties of logic languages, namely the existence of equivalent operational, model theo-retic and xpoint semantics. Moreover, since computatio...

متن کامل

A Hierarchy of Semantics for Normal

The diierent properties characterizing the operational behavior of logic programs can be organized in a hierarchy of xpoint semantics related by Galois insertions, having the least Herbrand model as most abstract semantics, and the SLD operational semantics as most concrete semantics. The choice of a semantics in the hierarchy allows to model precisely the program properties of interest while g...

متن کامل

Generative Modeling with Failure in PRISM

PRISM is a logic-based Turing-complete symbolicstatistical modeling language with a built-in parameter learning routine. In this paper,we enhance the modeling power of PRISM by allowing general PRISM programs to fail in the generation process of observable events. Introducing failure extends the class of definable distributions but needs a generalization of the semantics of PRISM programs. We p...

متن کامل

Relating weight constraint and aggregate programs: Semantics and representation

Weight constraint and aggregate programs are among the most widely used logic programs with constraints. In this paper, we relate the semantics of these two classes of programs, namely the stable model semantics for weight constraint programs and the answer set semantics based on conditional satisfaction for aggregate programs. Both classes of programs are instances of logic programs with const...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:
  • J. Log. Comput.

دوره 5  شماره 

صفحات  -

تاریخ انتشار 1995